1

从上一个问题,我得到这个代码

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

但后来我收到错误消息,名称 synset 未定义,任何人都可以向我解释为什么会发生这种情况?因为我搜索了同样的问题,但我仍然没有得到它

---------------------------------------------------------------------------
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

​
4

0 回答 0