Defining WordNetError
Asked Answered
A

1

6

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?

Agoraphobia answered 21/4, 2017 at 15:47 Comment(4)
Replace WordNetError by wordnet.WordNetError. And please, use a search engine next time, it's literally the first link.Heinous
@Heinous rude! I did and your solution doesn't workAgoraphobia
AttributeError: 'WordNetCorpusReader' object has no attribute 'WordNetError'Agoraphobia
@user30588703 My bad, yes it's in nltk.corpus.reader.wordnet. And yes, it can be considered rude to expect a little more research.Heinous
A
7
from nltk.corpus.reader.wordnet import WordNetError

Had to import WordNetError

Agoraphobia answered 21/4, 2017 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.