mirror of
https://codeberg.org/JasterV/sentences-crud.git
synced 2026-04-26 18:10:05 +00:00
aggregation script done
This commit is contained in:
parent
c3997c47fa
commit
c0c885064f
1 changed files with 37 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
||||||
|
const admin = require('firebase-admin')
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
|
||||||
|
if (args.length != 1) {
|
||||||
|
console.log('Firebase service account file required')
|
||||||
|
console.log('nodejs aggregate_words.js <account-file>')
|
||||||
|
process.exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const serviceAccount = require(args[0]);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
admin.initializeApp({
|
||||||
|
credential: admin.credential.cert(serviceAccount)
|
||||||
|
});
|
||||||
|
|
||||||
|
const db = admin.firestore()
|
||||||
|
|
||||||
|
console.log('Firestore credentials ok')
|
||||||
|
|
||||||
|
console.log('Reading sentences')
|
||||||
|
|
||||||
|
const sentencesRef = await db.collection('sentences').get()
|
||||||
|
|
||||||
|
const words = {}
|
||||||
|
|
||||||
|
sentencesRef.forEach((sentence) => {
|
||||||
|
const { text } = sentence.data()
|
||||||
|
text.trim().split(' ').forEach(word => words[word] = (words[word] ?? 0) + 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
Object.entries(words)
|
||||||
|
.sort((a, b) => b[1] - a[1])
|
||||||
|
.slice(0, 100)
|
||||||
|
.forEach((pair) => console.log(pair[0], pair[1]))
|
||||||
|
})();
|
||||||
Loading…
Reference in a new issue