开发者社区 问答 正文

从 WordNet 获取反义词

从 WordNet 获取反义词

展开
收起
珍宝珠 2019-12-03 15:04:47 951 分享 版权
1 条回答
写回答
取消 提交回答
  • 你唯一要做的是在将 lemmas 的结果加入数组之前,检查结果是否确实是一个正确的反义词。

    from nltk.corpus import wordnet
    antonyms = []
    for syn in wordnet.synsets("small"):
        for l in syn.lemmas():
            if l.antonyms():
                antonyms.append(l.antonyms()[0].name())
    print(antonyms)
    
    

    输出是:

    ['large', 'big', 'big']
    
    

    这就是 NLTK 在自然语言处理中的力量。

    2019-12-03 15:05:19
    赞同 展开评论
问答地址: