Reputation: 591
I have a list of terms in a sentence with sentiwordnet parts-of-speech, which I am attempting to sum over to find the net sentiment:
from nltk.corpus import sentiwordnet as swn, wordnet
score = 0
for term in terms:
try:
term = swn.senti_synset(term)
except WordNetError:
pass
score += term.pos_score() - term.neg_score()
Prior to adding the exception, I was getting WordNetError due to a particular synset not being present in the dict. Having now added the exception, I am receiving this error:
NameError: name 'WordNetError' is not defined
How do I resolve this?
Upvotes: 6
Views: 2159
Reputation: 591
from nltk.corpus.reader.wordnet import WordNetError
Had to import WordNetError
Upvotes: 7