Skip to content

Instantly share code, notes, and snippets.

View bee-san's full-sized avatar
🌻
Tending to my plants

Autumn (Bee) bee-san

🌻
Tending to my plants
View GitHub Profile
// get all text from .story-body within p tags on a BBC news web article
let $article = $('.story-body').find('p').text();
let $article = $('.story-body').find('p')
function TFIDF(documents){
// calculates TF*IDF
const TFVals = termFrequency(documents);
const IDFVals = inverseDocumentFrequency(documents);
let TFidfDict = {};
for (const [key, value] of Object.entries(TFVals)){
if (key in IDFVals){
TFidfDict[key] = TFVals[key] * IDFVals[key];
function TFIDF(documents){
// calculates TF*IDF
const TFVals = termFrequency(documents);
const IDFVals = inverseDocumentFrequency(documents);
let TFidfDict = {};
for (const [key, value] of Object.entries(TFVals)){
if (key in IDFVals){
TFidfDict[key] = TFVals[key] * IDFVals[key];
function TFIDF(documents){
// calculates TF*IDF
const TFVals = termFrequency(documents);
const IDFVals = inverseDocumentFrequency(documents);
let TFidfDict = {};
for (const [key, value] of Object.entries(TFVals)){
if (key in IDFVals){
TFidfDict[key] = TFVals[key] * IDFVals[key];
@bee-san
bee-san / idf3.js
Last active August 31, 2018 10:17
function inverseDocumentFrequency(document){
// calculates the inverse document frequency of every sentence
const words_without_stopwords = prettify(document);
const unique_words_set = uniqueWords(words_without_stopwords);
const sentences = document.split(".").map(item => item.trim());
sentences[0] = sentences[0].substring(146);
const lengthOfDocuments = sentences.length;
// prettifys each sentence so it doesn't have stopwords
@bee-san
bee-san / idf2.js
Last active August 27, 2018 13:16
function inverseDocumentFrequency(documents){
// calculates the inverse document frequency of every sentence
const words_without_stopwords = prettify(documents);
const sentences = documents.split(".")
sentences[0] = sentences[0].substring(146);
const lengthOfDocuments = sentences.length;
const WordCountDocuments = countWords(words_without_stopwords);
// calculate TF values of all documents
@bee-san
bee-san / idf.js
Last active August 31, 2018 10:07
function inverseDocumentFrequency(document){
// calculates the inverse document frequency of every sentence
const words_without_stopwords = prettify(document);
const unique_words_set = uniqueWords(words_without_stopwords);
const sentences = document.split(".").map(item => item.trim());
sentences[0] = sentences[0].substring(146);
const lengthOfDocuments = sentences.length;
// prettifys each sentence so it doesn't have stopwords
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);
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);