Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining WordNetError

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?

like image 305
user3058703 Avatar asked Apr 21 '17 15:04

user3058703


1 Answers

from nltk.corpus.reader.wordnet import WordNetError

Had to import WordNetError

like image 110
user3058703 Avatar answered Sep 30 '22 16:09

user3058703