I am getting this problem . my python code is

 for i,j in nltk.pos_tag(words):
        print i,j
        if 'JJ' in j:
            print "pj:" ,pj
        elif 'RB' in j:
            pr =(list(swn.senti_synsets(i,'r'))[0]).pos_score()
            print "pr:" ,pr
        elif 'NN' in j:
            pn =(list(swn.senti_synsets(i,'n'))[0]).pos_score()
            print "pn:" ,pn
        elif 'VB' in j:
            pv =(list(swn.senti_synsets(i,'v'))[0]).pos_score()
            print "pv:" ,pv

where "words" is a list of words containing adjective , adverb , noun etc..
words=['good','only','excellent','really'.........] nearly 300 such words. when i run this code it works for first 2 words .that is positive score of good and only will b displayed. but when it goes to word "excellent " there is this error..
good JJ
pj: 0.75
only RB
pr: 0.0
excellent JJ

    Traceback (most recent call last):
      File "C:\Python27\mat to file.py", line 39, in <module>
    IndexError: list index out of range

please help !!!!

Edited by lavanyarao

1 Year
Discussion Span
Last Post by Brandon Hatch

The list list(swn.senti_synsets(i,'a')) is probably the empty list [ ] You could check this by printing its repr() for example. Your program does not (yet) handle the case where this list is empty. You must add some code.

Votes + Comments
thanku..it was tagged wrongly

Also the example code and the example error message you gave us are different, the error message has pj+=(swn.senti_synsets(i,'a')[0]).pos_score() and the example code has pj=(list(swn.senti_synsets(i,'a'))[0]).pos_score(). Not sure what you're trying to accomplish with this code, but I'm pretty sure you get your error from code that wasn't shown in the example.

Votes + Comments
code has pj+=(list(swn.senti_synsets(i,'a')[0]).pos_score() . i forgot to include. thankyou.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.