[英]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: 我在一个带有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()
Prior to adding the exception, I was getting WordNetError due to a particular synset not being present in the dict. 在添加异常之前,我得到了WordNetError,因为dict中没有特定的synset。 Having now added the exception, I am receiving this error: 现在添加了异常,我收到此错误:
NameError: name 'WordNetError' is not defined
How do I resolve this? 我该如何解决这个问题?
from nltk.corpus.reader.wordnet import WordNetError
不得不导入WordNetError
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.