This file contains hidden or 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 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 |
This file contains hidden or 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
| { | |
| "manifest_version": 2, | |
| "name": "TL;DR - Summary of BBC news articles", | |
| "version": "1.0", | |
| "description": "This extension creates a summary of BBC news articles using TF*IDF", | |
| "icons": { | |
| "48": "icons/border-48.png" |
This file contains hidden or 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
| { | |
| "manifest_version": 2, | |
| "name": "TL;DR - Summary of BBC news articles", | |
| "version": "1.0", | |
| "description": "This extension creates a summary of BBC news articles using TF*IDF", | |
| "content_scripts": [ | |
| { | |
| "matches": ["*://www.bbc.co.uk/news/*"], | |
| "js": ["jquery.js", "tldr.js"] |
This file contains hidden or 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
| // get all text from .story-body within p tags on a BBC news web article | |
| let $article = $('.story-body').find('p').text(); | |
| // insert text into body of document | |
| let insert = $('.story-body').prepend(TFIDF($article)); |
This file contains hidden or 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
| // get all text from .story-body within p tags on a BBC news web article | |
| let $article = $('.story-body').find('p').text(); |
This file contains hidden or 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
| let $article = $('.story-body').find('p') |
This file contains hidden or 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 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]; |
This file contains hidden or 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 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]; |
This file contains hidden or 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 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]; |
This file contains hidden or 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 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 |