How to generate a list of antonyms for adjectives in WordNet using Python

I want to do the following in Python (I have the NLTK library, but I'm not very good with Python, so I wrote 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 

This means that I can create a complete dictionary of antonyms for adjectives. I think this should be doable, but I don't know how to create a Python script. I would like to do this in Python, as in the native language of NLTK.

+8
python nlp nltk wordnet
source share
1 answer
 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() 

Note that there will be reverse duplicates.

[exit]:

 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 ... 
+9
source share

All Articles