Last active
May 6, 2022 08:36
-
-
Save julienreszka/8f2f747f6319d04e30f3dc3802971064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wordFreq(string) { | |
var words = string.replace(/[.]/g, '').split(/\s/); | |
var freqMap = {}; | |
words.forEach(function(w) { | |
var lowerWord = w.toLowerCase() | |
if (!freqMap[lowerWord]) { | |
freqMap[lowerWord] = 0; | |
} | |
freqMap[lowerWord] += 1; | |
}); | |
var mostCommonWordsInEnglish =[ | |
"the", | |
"be", | |
"to", | |
"of", | |
"and", | |
"a", | |
"in", | |
"that", | |
"have", | |
"I", | |
"it", | |
"for", | |
"not", | |
"on", | |
"with", | |
"he", | |
"as", | |
"you", | |
"do", | |
"at", | |
"this", | |
"but", | |
"his", | |
"by", | |
"from", | |
"they", | |
"we", | |
"say", | |
"her", | |
"she", | |
"or", | |
"an", | |
"will", | |
"my", | |
"one", | |
"all", | |
"would", | |
"there", | |
"their", | |
"what", | |
"so", | |
"up", | |
"out", | |
"if", | |
"about", | |
"who", | |
"get", | |
"which", | |
"go", | |
"me", | |
"when", | |
"make", | |
"can", | |
"like", | |
"time", | |
"no", | |
"just", | |
"him", | |
"know", | |
"take", | |
"people", | |
"into", | |
"year", | |
"your", | |
"good", | |
"some", | |
"could", | |
"them", | |
"see", | |
"other", | |
"than", | |
"then", | |
"now", | |
"look", | |
"only", | |
"come", | |
"its", | |
"over", | |
"think", | |
"also", | |
"back", | |
"after", | |
"use", | |
"two", | |
"how", | |
"our", | |
"work", | |
"first", | |
"well", | |
"way", | |
"even", | |
"new", | |
"want", | |
"because", | |
"any", | |
"these", | |
"give", | |
"day", | |
"most", | |
"us" | |
] | |
var mostCommonWordsInFrench = [ | |
"le", "de", "un", "et", "être", "il", "avoir", "ne", "je", "son", "que", "se", "qui", "en", "ce", "dans", "du", "elle", "au", "de", "ce", "le", "pour", "pas", "que", "vous", "par", "sur", "faire", "plus", "dire", "me", "on", "mon", "lui", "nous", "comme", "mais", "pouvoir", "avec", "tout", "y", "aller", "voir", "en", "bien", "où", "sans", "tu", "ou", "leur", "homme", "si", "deux", "mari", "moi", "vouloir", "te", "femme", "venir", "quand", "grand", "celui", "si", "notre", "devoir", "là", "jour", "prendre", "même", "votre", "tout", "rien", "encore", "petit", "aussi", "quelque", "dont", "tout", "mer", "trouver", "donner", "temps", "ça", "peu", "même", "falloir", "sous", "parler", "alors", "main", "chose", "ton", "mettre", "vie", "savoir", "yeux", "passer", "autre", "après" | |
] | |
return Object.keys(freqMap).map(k=>{return {word: k,freq:freqMap[k]}}) | |
.filter((w)=>w.freq > 1 && !mostCommonWordsInEnglish.includes(w.word) && !mostCommonWordsInFrench.includes(w.word)) | |
.sort((a,b)=>b.freq-a.freq); | |
} | |
wordFreq(document.body.innerText) |
Author
julienreszka
commented
Feb 16, 2022
Most common words in French
https://github.com/nmondon/mots-frequents/blob/master/frequence.csv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment