Python 定义WordNetError

Python 定义WordNetError,python,nltk,wordnet,senti-wordnet,Python,Nltk,Wordnet,Senti Wordnet,我有一个包含sentiwordnet词类的句子中的术语列表,我试图对其进行总结,以发现网络情绪: from nltk.corpus import sentiwordnet as swn, wordnet score = 0 for term in terms: try: term = swn.senti_synset(term) except WordNetError:

我有一个包含sentiwordnet词类的句子中的术语列表,我试图对其进行总结,以发现网络情绪:

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()
在添加异常之前,我收到WordNetError,因为dict中不存在特定的语法集。现在添加异常后,我收到此错误:

NameError: name 'WordNetError' is not defined
我如何解决这个问题

from nltk.corpus.reader.wordnet import WordNetError

不得不导入WordNetError

WordNetError
替换为
wordnet.WordNetError
。请下次使用搜索引擎,它实际上是第一个链接。@dhke rude!我做了,但你的解决方案不起作用AttributeError:'WordNetCorpusReader'对象没有属性'WordNetError'@User3058803我的错,是的,它在
nltk.corpus.reader.wordnet
中。是的,期待更多的研究是不礼貌的。