NameError: name 'synset' is not defined

534 Views Asked by At

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

​
1

There are 1 best solutions below

1
On

from nltk.corpus import wordnet as wn

Importing this module may solve this problem.