diff --git a/vaderSentiment/vaderSentiment.py b/vaderSentiment/vaderSentiment.py index 0690c44..91486fe 100644 --- a/vaderSentiment/vaderSentiment.py +++ b/vaderSentiment/vaderSentiment.py @@ -287,7 +287,7 @@ def sentiment_valence(self, valence, sentitext, item, i, sentiments): valence = self.lexicon[item_lowercase] # check for "no" as negation for an adjacent lexicon item vs "no" as its own stand-alone lexicon item - if item_lowercase == "no" and words_and_emoticons[i + 1].lower() in self.lexicon: + if item_lowercase == "no" and i != len(words_and_emoticons)-1 and words_and_emoticons[i + 1].lower() in self.lexicon: # don't use valence of "no" as a lexicon item. Instead set it's valence to 0.0 and negate the next item valence = 0.0 if (i > 0 and words_and_emoticons[i - 1].lower() == "no") \