热线电话:13121318867

登录
2019-03-18 阅读量: 815
python如何识别单词的同义词和反义词

我们如何识别单词的同义词和反义词?引理将是同义词,然后您可以使用.antonyms来查找引理的反义词。因此,我们可以填充一些列表,如:

import nltk

from nltk.corpus import wordnet

synonyms = []

antonyms = []

for syn in wordnet.synsets("good"):

for l in syn.lemmas():

synonyms.append(l.name())

if l.antonyms():

antonyms.append(l.antonyms()[0].name())

print(set(synonyms))

print(set(antonyms))

输出将是两组同义词和反义词

{‘beneficial’, ‘just’, ‘upright’, ‘thoroughly’, ‘in_force’, ‘well’, ‘skilful’, ‘skillful’, ‘sound’, ‘unspoiled’, ‘expert’, ‘proficient’, ‘in_effect’, ‘honorable’, ‘adept’, ‘secure’, ‘commodity’, ‘estimable’, ‘soundly’, ‘right’, ‘respectable’, ‘good’, ‘serious’, ‘ripe’, ‘salutary’, ‘dear’, ‘practiced’, ‘goodness’, ‘safe’, ‘effective’, ‘unspoilt’, ‘dependable’, ‘undecomposed’, ‘honest’, ‘full’, ‘near’, ‘trade_good’} {‘evil’, ‘evilness’, ‘bad’, ‘badness’, ‘ill’}

11.8676
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子