How to Use WordNet in Python
WordNet is an English word reference which is a piece of Natural Language Tool Kit (NLTK) for Python. This is a broad library worked to make Natural Language Processing (NLP) simple. Some fundamental capacities will be examined in this article. To begin using WordNet, you need to import it first:
from nltk.corpus import wordnet
Synsets and Lemmas
In WordNet, comparative words are assembled into a set known as a Synset (short for Synonym-set). Each Synset has a name, a grammatical feature, and a number. The words in a Synset are known as Lemmas.
Getting Synsets
The capacity wordnet.synsets('word') returns an exhibit containing every one of the Synsets identified with the word passed to it as the contention.
Model:
print(wordnet.sysnets('room'))
Yield:
[Synset('room.n.01'), Synset('room.n.02'), Synset('room.n.03'), Synset('room.n.04'), Synset('board.v.02')]
The technique returned five Synsets; four have the name 'room' and are a things, while the last one's name is 'board' and is an action word. The yield likewise recommends that the word 'room' has a total of five meanings or settings.
Read our Latest Blog on Python: Scope of variables in python
Getting definition of a Synset
By using definition(), a single Synset can additionally be investigated for a definition normal to every one of the Lemmas it contains. This strategy returns a string, which is the normal definition. There are two different ways to do this:
We can use the exhibit returned by synsets('word') and access one of its components:
syn_arr = wordnet.synsets('room')
syn_arr[0].definition()
Yield :
a region within a building encased by dividers and floor and ceiling
Or then again, pass the name of the Synset, its grammatical feature and its number, to synset() and afterward use definition():
wordnet.synset('room.n.02').definition()
Yield :
space for development
Getting all Lemmas of a Synset
Also, lemma_names() can be used in two different ways to return a variety of all Lemma names:
print(syn_arr[1].lemma_names())
# or
print(wordnet.synset('board.v.02').lemma_names())
Yield :
[u'room', u'way', u'elbow_room']
[u'board', u'room']
svg watcher
Using synets(), synset(), definition() and lemma_names()
Hyponyms
A Hyponym is a specialization of a Synset. It very well may be considered as a youngster (or inferred) class in inheritance. The capacity hyponyms() returns an exhibit containing every one of the Synsets which are Hyponyms of the given Synset:
print(wordnet.synset('calendar.n.01').hyponyms())
Yield :
[Synset('lunar_calendar.n.01'), Synset('lunisolar_calendar.n.01'), Synset('solar_calendar.n.01')]
Hypernyms
A Hypernym is a speculation of a Synset (for example something contrary to a Hyponym). A cluster containing all Hypernyms of a Synset is returned by hypernyms():
print(wordnet.synset('solar_calendar.n.01').hypernyms())
Yield :
[Synset('calendar.n.01')]
To learn more about wordnet, Click Here















