Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list index out of range error persists... #146

Open
iriumxx1 opened this issue Jun 10, 2023 · 2 comments
Open

list index out of range error persists... #146

iriumxx1 opened this issue Jun 10, 2023 · 2 comments

Comments

@iriumxx1
Copy link

iriumxx1 commented Jun 10, 2023

Hi I'm having the same problem as in the issue #91 (comment), 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"

@gdet
Copy link

gdet commented Sep 13, 2023

Hello! Did you find any solution?

@Siddharth-Latthe-07
Copy link

Siddharth-Latthe-07 commented Jun 27, 2024

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 an IndexError.
Try out these changes and tell if it works or not?

  1. Preprocess the Text:-
    Ensure that the input text does not end with "no". You can add a space or another character to the end of the text to avoid this issue
def preprocess_text(text):
    if text.strip().endswith("no"):
        text += " "
    return text

texto = preprocess_text(texto)
probas_vader = analyzer_vader.polarity_scores(texto)
  1. 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:
        #existing logic here

plz let me know if it works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants