0

I am getting this problem . my python code is

 for i,j in nltk.pos_tag(words):
        print i,j
        if 'JJ' in j:
            pj=(list(swn.senti_synsets(i,'a'))[0]).pos_score()
            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..
output:
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>
        pj+=(swn.senti_synsets(i,'a')[0]).pos_score()
    IndexError: list index out of range

please help !!!!

Edited by lavanyarao

3
Contributors
2
Replies
37
Views
11 Months
Discussion Span
Last Post by Brandon Hatch
Featured Replies
  • 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. Read More

1

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.

Comments
thanku..it was tagged wrongly
2

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.

Comments
code has pj+=(list(swn.senti_synsets(i,'a')[0]).pos_score() . i forgot to include. thankyou.
This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.