You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
770 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const fs = require('fs');
const lodash = require('lodash');
const csv = require('fast-csv');
// 读取CSV文件跳过有问题的行并给出警告
csv.parseFile('chat.txt', { headers: true }, (err, data) => {
if (err) throw err;
const keyword = 'ai';
const keywordData = data.filter(item => item.chat.includes(keyword));
const wordCounts = lodash.countBy(data, 'chat');
const top8Common = lodash.takeOrdered(wordCounts, 8, lodash.identity);
const stats = {
Keyword: keyword,
Count: keywordData.length,
};
const results = {
stats: [stats],
top8: top8Common,
keywordData: keywordData,
};
fs.writeFileSync('statistics.json', JSON.stringify(results, null, 2), 'utf-8');
});