-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable no-console */
const {
getMapByMonth,
monthNameMap,
readMeta,
wordCountMapToArray
} = require('./util')
function main() {
const processed_text_dir = process.argv[2]
const meta = readMeta(processed_text_dir)
printDataByMonth(getMapByMonth(meta))
}
function printDataByMonth(mapByMonth) {
const maxWords = 15
const encabezado = ['mes discurso', 'año discurso']
for (let i = 1; i <= maxWords; i++) {
encabezado.push('palabra ' + i)
encabezado.push('cantidad palabra ' + i)
}
console.log(encabezado.join('\t'))
Object.keys(mapByMonth).sort().forEach(k => {
const wordsCount = wordCountMapToArray(mapByMonth[k]).slice(0, maxWords)
// rellenar el arreglo para que tenga maxWords palabras
for (let i = wordsCount.length + 1; i <= maxWords; i++) {
wordsCount.push({word: 'NULL', count: 0})
}
const formattedCount = wordsCount.map(word => word.word + '\t' + word.count).join('\t')
console.log(monthNameMap[k.split('_')[1]] + '\t' + k.split('_')[0] + '\t' + formattedCount)
})
}
main()