如何使用 Python 在 WordNet 中生成形容词的反义词列表 [英] How to generate a list of antonyms for adjectives in WordNet using Python

查看:31
本文介绍了如何使用 Python 在 WordNet 中生成形容词的反义词列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Python 中执行以下操作(我有 NLTK 库,但我不擅长 Python,所以我用奇怪的伪代码编写了以下内容):

I want to do the following in Python (I have the NLTK library, but I'm not great with Python, so I've written the following in a weird pseudocode):

from nltk.corpus import wordnet as wn  #Import the WordNet library
for each adjective as adj in wn        #Get all adjectives from the wordnet dictionary
    print adj & antonym                #List all antonyms for each adjective 
once list is complete then export to txt file

这样我就可以生成一个完整的形容词反义词词典.我认为它应该是可行的,但我不知道如何创建 Python 脚本.我想用 Python 来做这件事,因为这是 NLTK 的母语.

This is so I can generate a complete dictionary of antonyms for adjectives. I think it should be doable, but I don't know how to create the Python script. I'd like to do it in Python as that's the NLTK's native language.

推荐答案

from nltk.corpus import wordnet as wn

for i in wn.all_synsets():
    if i.pos() in ['a', 's']: # If synset is adj or satelite-adj.
        for j in i.lemmas(): # Iterating through lemmas for each synset.
            if j.antonyms(): # If adj has antonym.
                # Prints the adj-antonym pair.
                print j.name(), j.antonyms()[0].name()

注意会有反向重复.

[输出]:

able unable
unable able
abaxial adaxial
adaxial abaxial
acroscopic basiscopic
basiscopic acroscopic
abducent adducent
adducent abducent
nascent dying
dying nascent
abridged unabridged
unabridged abridged
absolute relative
relative absolute
absorbent nonabsorbent
nonabsorbent absorbent
adsorbent nonadsorbent
nonadsorbent adsorbent
absorbable adsorbable
adsorbable absorbable
abstemious gluttonous
gluttonous abstemious
abstract concrete
...

这篇关于如何使用 Python 在 WordNet 中生成形容词的反义词列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆