def _suggest_synonyms(self, target_words, words):
suggestions = []
word_synonyms = [(Word(w[0]).get_synsets(pos=VERB), w[1]) for w in target_words]
for w in words:
found = False
synset = (Word(w[0]).get_synsets(pos=VERB), w[1])
if len(synset[0]):
for synonym in [s for s in word_synonyms if len(s[0])]:
similarity = synset[0][0].path_similarity(synonym[0][0])
if similarity == 1.0:
found = True
if 1.0 > similarity > 0.4 and not found:
suggestions.append((synset[0][0].name().split(".")[0], synonym[0][0].name().split(".")[0]))
return suggestions
评论列表
文章目录