cjhutto / vaderSentiment

VADER Sentiment Analysis. VADER (Valence Aware Dictionary and sEntiment Reasoner) is a lexicon and rule-based sentiment analysis tool that is specifically attuned to sentiments expressed in social media, and works well on texts from other domains.
MIT License
4.43k stars 1k forks source link

List index out of range error for an edge case #91

Closed haroonkn closed 4 years ago

haroonkn commented 4 years ago

In vaderSentiment.py, line 287:

if item_lowercase == "no" and words_and_emoticons[i + 1].lower() in self.lexicon: valence = 0.0

This errors out on the edge case where the last word is no. Like in the following example:

Overall Food: 1-5 Drink: 3-5 (beer) Service: 1-5 Come back: no

Would probably need to update the line to check if its the last word.

Aksa123-TS commented 4 years ago

Shall I create a branch to add a new line to check if its the last word?

cjhutto commented 4 years ago

(great find, thanks) updated line 287 to address this... does this close the issue you were having?

Aksa123-TS commented 4 years ago

Thank you for the fixing, It works great now.

LeanMestra commented 1 year ago

Hi! I think I´m having the same or related issue as haroonkn . I´m running the last version of vaderSentiment

~\anaconda3\lib\site-packages\vaderSentiment\vaderSentiment.py in sentiment_valence(self, valence, sentitext, item, i, sentiments) 288 valence = 0.0 289 if (i > 0 and words_and_emoticons[i - 1].lower() == "no") \ --> 290 or (i > 1 and words_and_emoticons[i - 2].lower() == "no") \ 291 or (i > 2 and words_and_emoticons[i - 3].lower() == "no" and words_and_emoticons[i - 1].lower() in ["or", "nor"] ): 292 valence = self.lexicon[item_lowercase] * N_SCALAR

IndexError: list index out of range