Library - Natural Language Toolkit

Back to Course

Lesson Description

Lession - #533 Looking up words in Wordnet

What is Wordnet?

Wordnet is a huge lexical database of English, which was made by Princeton. It is a piece of the NLTK corpus.Nouns, verbs, adjectives and adverbs all are assembled into set of synsets, i.e., cognitive equivalents. Here each arrangement of synsets express a particular significance. Following are some utilization instances of Wordnet −
  • Looking into the meaning of a word can be utilized
  • We can track down equivalents and antonyms of a word
  • Word relations and likenesses can be investigated utilizing Wordnet
  • Word sense disambiguation for those words having various purposes and definitions

How to import Wordnet?

Wordnt can be imported with the assistance of following command −
from nltk.corpus import wordnet

For more compact command, use the following −
from nltk.corpus import wordnet as wn

Synset instances

Synset are groupings of equivalents words that express a similar idea. At the point when you use Wordnet to look into words, you will get a list of Synset occurrences.

To get a list of Synsets, we can look into any word in Wordnet by utilizing wordnet.synsets(word>
. For instance, in next Python recipe, we will look into the Synset for the 'canine' alongside certain properties and strategies for Synset −

To start with, import the wordnet as follows −
from nltk.corpus import wordnet as wn

Now, provide the word you want to look up the Synset for −
syn = wn.synsets('dog'>

Here, we are using name(>
method to get the unique name for the synset which can be used to get the Synset directly −
Output: 'dog.n.01'

Next, we are using definition(>
method which will give us the definition of the word −
Output: 'a member of the genus Canis (probably descended from the common wolf>
that has been domesticated by man since prehistoric times; occurs in many breeds'

Another method is examples(>
which will give us the examples related to the word −
Output: ['the dog barked all night']

Complete implementation example
from nltk.corpus import wordnet as wn
syn = wn.synsets('dog'>
[0] syn.name(>

Getting Hypernyms

Synsets are coordinated in a legacy tree like structure in which Hypernyms addresses more preoccupied terms while Hyponyms addresses the more unambiguous terms. One of the significant things is that this tree can be followed the entire way to a root hypernym. Allow us to grasp the idea with the assistance of the accompanying model −
from nltk.corpus import wordnet as wn
syn = wn.synsets('dog'>
[0] syn.hypernyms(>

, Synset('domestic_animal.n.01'>

Lemmas in Wordnet

In phonetics, the canonical form or morphological form of a word is known as a lemma. To find an synonym as well as antonym of a word, we can likewise query lemmas in WordNet. Allow us to perceive how.

Tracking down Synonyms
By utilizing the lemma(>
technique, we can track down the quantity of synonyms of a Synset. Allow us to apply this strategy on 'dog' synset −

from nltk.corpus import wordnet as wn
syn = wn.synsets('dog'>
[0] lemmas = syn.lemmas(>


The above output shows ‘dog’ has three lemmas.
Getting the name of the first lemma as follows −
Output: 'dog'

Getting the name of the second lemma as follows −
Output: 'domestic_dog'

Getting the name of the third lemma as follows −
Output: 'Canis_familiaris'