我的循环有问题。如果该意义的任何引理与 word2 匹配,我需要它只打印一次“同义词”,否则“不是同义词”,但只打印一次。
from nltk.corpus import wordnet as wn
word1 = 'motorcar'
word2 = 'automobile'
for syn in wn.synsets(word1):
for lemma in syn.lemma_names():
if lemma == word2 and lemma != word1:
print('Synonyms')
elif all(syn.lemma_names()) != word2:
print('not synonyms')