In this Python NLP lesson we are going to learn about Python NLP Wordnet, so Wordnet is a dictionary or word database for English language and it is mostly used for Natural Language Processing(NLP). and Synset is used for searching of the words in the Wordnet. Some of the words have only one Synset and some have several.
Now let’s create an example and we are going to check the Synset of hello .
1 2 3 4 5 6 |
from nltk.corpus import wordnet as wn wn_hello = wn.synsets('hello') print(wn_hello) |
If you run the code you will see that we have just one Synset for hello .
1 |
[Synset('hello.n.01')] |
Now we can find the definition and examples for this hello word.
1 2 3 4 5 6 7 8 9 10 |
from nltk.corpus import wordnet as wn wn_hello = wn.synsets('hello') hello = wn.synset('hello.n.01') print("Definition : ", hello.definition()) print("Name : ", hello.name()) print("Example : " , hello.examples()) |
If you run the code this will be the result.
1 2 3 |
Definition : an expression of greeting Name : hello.n.01 Example : ['every morning they exchanged polite hellos'] |
As i have said some of the words have only one Synset and some have several. now we are going to check the clear word and you will see that there are different Synsets for the clear word.
1 2 3 4 5 |
from nltk.corpus import wordnet as wn wn_clear = wn.synsets('clear') print(wn_clear) |
This will be the result.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[Synset('clear.n.01'), Synset('open.n.01'), Synset('unclutter.v.01'), Synset('clear.v.02'), Synset('clear_up.v.04'), Synset('authorize.v.01'), Synset('clear.v.05'), Synset('pass.v.09'), Synset('clear.v.07'), Synset('clear.v.08'), Synset('clear.v.09'), Synset('clear.v.10'), Synset('clear.v.11'), Synset('clear.v.12'), Synset('net.v.02'), Synset('net.v.01'), Synset('gain.v.08'), Synset('clear.v.16'), Synset('clear.v.17'), Synset('acquit.v.01'), Synset('clear.v.19'), Synset('clear.v.20'), Synset('clear.v.21'), Synset('clear.v.22'), Synset('clear.v.23'), Synset('clear.v.24'), Synset('clear.a.01'), Synset('clear.s.02'), Synset('clear.s.03'), Synset('clear.a.04'), Synset('clear.s.05'), Synset('clear.s.06'), Synset('clean.s.03'), Synset('clear.s.08'), Synset('clear.s.09'), Synset('well-defined.a.02'), Synset('clear.a.11'), Synset('clean.s.02'), Synset('clear.s.13'), Synset('clear.s.14'), Synset('clear.s.15'), Synset('absolved.s.01'), Synset('clear.s.17'), Synset('clear.r.01'), Synset('clearly.r.04')] |
You can find the definition for the specific Synset.
1 2 3 4 5 |
from nltk.corpus import wordnet as wn clear_07 = wn.synset('clear.v.07') print(clear_07.definition()) |
Let’s just find the definitions in a range.
1 2 3 4 5 6 7 8 9 10 11 |
from nltk.corpus import wordnet as wn wn_clear = wn.synsets('clear') for i in range(0,7): clear = wn_clear[i] print("Name : " , clear.name()) print("Definition : ", clear.definition()) print("Example : ", clear.examples()) |