-
-
Save felixdorn/ba9b8b58c310d0fde40f9cd96a438fde 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
// words is an array of words (strings) | |
getSentiment(words) { | |
var score = 0; | |
var negator = 1; | |
var nrHits = 0; | |
words.forEach((token) => { | |
var lowerCased = token.toLowerCase(); | |
if (this.negations.indexOf(lowerCased) > -1) { | |
negator = -1; | |
nrHits++; | |
} | |
else { | |
// First try without stemming | |
if (this.vocabulary[lowerCased] != undefined) { | |
score += negator * this.vocabulary[lowerCased]; | |
nrHits++; | |
} | |
else { | |
if (this.stemmer) { | |
var stemmedWord = this.stemmer.stem(lowerCased); | |
if(this.vocabulary[stemmedWord] != undefined) { | |
score += negator * this.vocabulary[stemmedWord]; | |
nrHits++; | |
} | |
} | |
} | |
} | |
}); | |
score = score / words.length; | |
return score; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment