1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 14:34:19 +00:00
pds-2021-g2-nest/nest_frontend/utils/countTweetWords.js

29 lines
636 B
JavaScript
Raw Normal View History

2021-05-20 10:15:13 +00:00
import sw from "stopword"
const stopwords = [...sw.it, ...sw.en, "rt"]
2021-05-25 02:06:14 +00:00
export default function countTweetWords(tweets = []) {
2021-05-20 10:15:13 +00:00
let words = {}
for(const tweet of tweets) {
if(!tweet.content) {
continue
}
for(const word of tweet.content.toLowerCase().split(/\s+/)) {
2021-05-20 10:16:01 +00:00
if(stopwords.includes(word)) {
continue
}
if(word.startsWith("https://")) {
continue
}
2021-05-20 10:15:13 +00:00
if(!words.hasOwnProperty(word)) {
words[word] = 0
}
words[word] += 1
}
}
return words
}