Python - WordNet Interface


Advertisements

WordNet is a dictionary of English, similar to a traditional thesaurus NLTK includes the English WordNet. We can use it as a reference for getting the meaning of words, usage example and definition. A collection of similar words is called lemmas. The words in WordNet are organized and nodes and edges where the nodes represent the word text and the edges represent the relations between the words. below we will see how we can use the WordNet module.

All Lemmas

from nltk.corpus import wordnet as wn
res=wn.synset('locomotive.n.01').lemma_names()
print res

When we run the above program, we get the following output −

[u'locomotive', u'engine', u'locomotive_engine', u'railway_locomotive']

Word Definition

The dictionary definition of a word can be obtained by using the definition function. It describes the meaning of the word as we can find in a normal dictionary.

from nltk.corpus import wordnet as wn
resdef = wn.synset('ocean.n.01').definition()
print resdef

When we run the above program, we get the following output −

a large body of water constituting a principal part of the hydrosphere

Usage Examples

We can get the example sentences showing some usage examples of the words using the exmaples() function.

from nltk.corpus import wordnet as wn
res_exm = wn.synset('good.n.01').examples()
print res_exm

When we run the above program we get the following output −

['for your own good', "what's the good of worrying?"]

Opposite Words

Get All the opposite words by using the antonym function.

from nltk.corpus import wordnet as wn
# get all the antonyms
res_a = wn.lemma('horizontal.a.01.horizontal').antonyms()
print res_a

When we run the above program we get the following output −

[Lemma('inclined.a.02.inclined'), Lemma('vertical.a.01.vertical')]

Useful Video Courses


Video

Python Online Training

187 Lectures 17.5 hours

Malhar Lathkar

Video

Python Essentials Online Training

55 Lectures 8 hours

Arnab Chakraborty

Video

Learn Python Programming in 100 Easy Steps

136 Lectures 11 hours

In28Minutes Official

Video

Python with Data Science

Best Seller

75 Lectures 13 hours

Eduonix Learning Solutions

Video

Python 3 from scratch to become a developer in demand

Best Seller

70 Lectures 8.5 hours

Lets Kode It

Video

Python Data Science basics with Numpy, Pandas and Matplotlib

Most Popular

63 Lectures 6 hours

Abhilash Nelson

Advertisements