Skip to content

Instantly share code, notes, and snippets.

@bee-san
Last active August 31, 2018 09:37
Show Gist options
  • Select an option

  • Save bee-san/a71574562fbf15ab9e855fdf2d7d0592 to your computer and use it in GitHub Desktop.

Select an option

Save bee-san/a71574562fbf15ab9e855fdf2d7d0592 to your computer and use it in GitHub Desktop.
function termFrequency(document){
// calculates term frequency of each sentence
words_without_stopwords = prettify(document);
// gets rid of trailing spaces
const sentences = document.split(".").map(item => item.trim());
sentences[0] = sentences[0].substring(146);
const TFVals = countWords(words_without_stopwords)
const unique_words = uniqueWords(words_without_stopwords);
// actually makes it TF values according to formula
for (const [key, value] of Object.entries(TFVals)){
TFVals[key] = TFVals[key] / words_without_stopwords.length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment