Claude COULOMBE
Claude COULOMBE

Reputation: 3738

How to get a list of antonyms lemmas using Python, NLTK and WordNet?

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.

Upvotes: 3

Views: 1213

Answers (1)

Claude COULOMBE
Claude COULOMBE

Reputation: 3738

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/

Upvotes: 4

Related Questions