I am trying to find average differences in sentiment for all antonyms in synsets using the function
def check_antonym_similar(wnd, senti):
"""
find the average difference for all synsets that have antonyms
and which have non-zero sentiment
"""
diffs = []
## look at all the synsets we have sentiment for
for ssid1 in senti:
ss1 = wnd.synset(id=ssid1) # get the synset
for lemma in ss1.lemmas(): # get lemmas
# Find antonyms for each lemma
for antonym in lemma.antonyms():
ssid2 = antonym.synset().id
## check if we have sentiment for the antonym
if (ssid2 in senti) \
and senti[ssid2] != 0.0 and senti[ssid1] != 0.0:
## keep only non-zero sentiments
diff = abs(senti[ssid2] - senti[ssid1])
diffs.append(diff)
if len(diffs) > 0:
return sum(diffs)/len(diffs)
else:
return 0.0
antonym_diff = check_antonym_similar(ewn, ss_senti)
print(f"Average difference in non-zero sentiment for antonyms {antonym_diff:.2f}")
When I checked the types using
for ssid in list(ss_senti.keys())[:5]:
ss = ewn.synset(id=ssid) # get the synset
lemmas = ss.lemmas() # get lemmas
for lemma in lemmas:
print(f"Lemma: {lemma}, Type: {type(lemma)}")
It did prove that the lemmas in wd are wd.Forms making them not unusable with .antonyms()
Is there some change in WordNet causing this problem? I wasn't able to find anything in the documentation nor did it even mention antonyms at all.