Created
August 3, 2018 15:58
-
-
Save adatta02/9b9336398c55569bd78f1904f7fe183c to your computer and use it in GitHub Desktop.
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
getWordCloudCounts(reviews: string[]): {} { | |
const words = {}; | |
const numReviews = reviews.length; | |
const wordCounts: IWordCount[] = []; | |
const stopWords = StopWords.get(); | |
for (let i = 0; i < numReviews; i++) { | |
reviews[i] = reviews[i].toString(); | |
const splitter = reviews[i].toLowerCase().split(' '); | |
for (let j = 0; j < splitter.length; j++) { | |
if (splitter[j].endsWith('.') || splitter[j].endsWith(',') || splitter[j].endsWith('?') || splitter[j].endsWith('!') | |
|| splitter[j].endsWith(';') || splitter[j].endsWith(':') || splitter[j].endsWith('"') || splitter[j].endsWith('\'') | |
|| splitter[j].endsWith('&') || splitter[j].endsWith(')')) { | |
splitter[j] = splitter[j].slice(0, -1); | |
} | |
if (splitter[j].startsWith('"') || splitter[j].startsWith('\'') || splitter[j].startsWith('&') || splitter[j].startsWith(' ') | |
|| splitter[j].startsWith('(')) { | |
splitter[j] = splitter[j].slice(1); | |
} | |
if (splitter[j].endsWith('."')) { | |
splitter[j] = splitter[j].slice(0, -1); | |
splitter[j] = splitter[j].slice(0, -1); | |
} | |
if ((!(splitter[j] in words) && splitter[j].length > 3)) { | |
words[splitter[j]] = 1; | |
} | |
else if (splitter[j].length > 3){ | |
words[splitter[j]]++; | |
} | |
} | |
} | |
return words; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment