简体   繁体   English

NameError: 名称 'synset' 未定义

[英]NameError: name 'synset' is not defined

From previous question, I get this code从上一个问题,我得到这段代码

print("Array..............\n\n")
tagged=np.array(df['tagged_texts'])
temp = []
for x in tagged: 
    for y in x: 
        temp.append(y) 
tagged = temp
print(tagged)
pos=neg=obj=count=0
for word, tag in tagged:
    ss_set = []
    if 'NN' in tag and swn.senti_synsets(word):
        ss_set = list(swn.senti_synsets(word))
    elif 'VB' in tag and swn.senti_synsets(word):
        ss_set = list(swn.senti_synsets(word))[0]
    elif 'JJ' in tag and swn.senti_synsets(word):
         ss_set = list(swn.senti_synsets(word))[0]
    elif 'RB' in tag and swn.senti_synsets(word):
         ss_set = list(swn.senti_synsets(word))[0]
    if ss_set:
        pos=pos+synset.pos_score()
        neg=neg+synset.neg_score()
        obj=obj+synset.obj_score()
        count+=1
final_score=pos-neg
print(final_score)
df['final_score']=final_score

But then I get error message that name synset is not defined, anyone can explain to me why this happened?但是后来我收到错误消息,指出名称同义词集未定义,任何人都可以向我解释为什么会这样? because I search the same question but I still didnt get to it因为我搜索了同样的问题,但我还是没找到

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-17-aa5a5112919f> in <module>
     11          ss_set = list(swn.senti_synsets(word))[0]
     12     if ss_set:
---> 13         pos=pos+synset.pos_score()
     14         neg=neg+synset.neg_score()
     15         obj=obj+synset.obj_score()

NameError: name 'synset' is not defined

​

from nltk.corpus import wor.net as wn

Importing this module may solve this problem.导入这个模块可能会解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM