Open iriumxx1 opened 1 year ago
Hello! Did you find any solution?
The above issue might appears to be related to the way it processes the word "no" when it is at the end of a sentence. Specifically, the code tries to access the next word after "no", which does not exist, resulting in anIndexError
.
Try out these changes and tell if it works or not?
def preprocess_text(text):
if text.strip().endswith("no"):
text += " "
return text
texto = preprocess_text(texto) probas_vader = analyzer_vader.polarity_scores(texto)
2. Try upgrading the vader sentiment library
OR the last case you can do is that, modify the library code to handle the above edge case:-
This involves adding a check to ensure that the index does not go out of range.
Find the `vaderSentiment.py` file in your `site-packages` directory and locate the `sentiment_valence` function. Modify the function to include a check for the length of `words_and_emoticons`:
def sentiment_valence(self, valence, sentitext, item, i, sentiments): item_lowercase = item.lower() if item_lowercase == "no" and i + 1 < len(sentitext.words_and_emoticons) and sentitext.words_and_emoticons[i + 1].lower() in self.lexicon:
plz let me know if it works?
Hi I'm having the same problem as in the issue https://github.com/cjhutto/vaderSentiment/issues/91#issuecomment-1550187600, and I'm using the last version:
Cell In[41], line 3 in deteccion_sentimiento_vader probas_vader = analyzer_vader.polarity_scores(texto)
File ~\anaconda3\lib\site-packages\vaderSentiment\vaderSentiment.py:273 in polarity_scores sentiments = self.sentiment_valence(valence, sentitext, item, i, sentiments)
File ~\anaconda3\lib\site-packages\vaderSentiment\vaderSentiment.py:290 in sentiment_valence if item_lowercase == "no" and words_and_emoticons[i + 1].lower() in self.lexicon:
IndexError: list index out of range
This error appears with a sentence that's ends with "no"