3

I would like to generate a list of antonyms lemmas of a given lemma using Python, NLTK, and WordNet. In fact I just want to share a small utility function.

Claude COULOMBE
  • 3,434
  • 2
  • 36
  • 39
  • See also https://stackoverflow.com/questions/24192979/how-to-generate-a-list-of-antonyms-for-adjectives-in-wordnet-using-python – alvas Nov 23 '17 at 00:53

1 Answers1

4

A simple Python and NLTK function that returns a list of antonyms

from nltk.corpus import wordnet as wn

def get_antonyms(input_lemma):
    antonyms = []
    for syn in wn.synsets(input_lemma):
        for lemma in syn.lemmas():
            if lemma.antonyms():
                antonyms.append(lemma.antonyms()[0].name())
    return antonyms

Related works: How to generate a list of antonyms for adjectives in WordNet using Python and http://www.geeksforgeeks.org/get-synonymsantonyms-nltk-wordnet-python/

Claude COULOMBE
  • 3,434
  • 2
  • 36
  • 39