NLP | Synsets for a word in WordNet



Synset — it is a special kind of simple interface that NLTK provides for searching words in WordNet. Instances of Synset — they are groups of synonymous words that express the same concept. Some words only have one Synset, and some — several.

Code # 1: Understanding Synset

from nltk.corpus import wordnet

syn = wordnet.synsets ( `hello` ) [ 0 ]

 

print ( "Synset name: " , syn.name ())

 
# Word definition

print ( "Synset meaning:" , syn.defin ition ())

 
# list of phrases using the word in context

print ( "Synset example:" , syn.examples ())

Exit :

 Synset name: hello.n.01 Synset meaning: an expression of greeting Synset example: [`every morning they exchanged polite hellos`]  

wordnet.synsets(word) can be used to get a list of Synsets. This list can be empty (if no such word is found), or it can contain multiple items.

Hypernyms and Hyponyms —

Hypernyms : more abstract terms
Hyponyms: more specific terms.

Both are manifested in the fact that Synsets are organized in a structure similar to that of a tree inheritance. This tree can be traced back to the hyper root. Hyperonyms provide a way to categorize and group words based on their similarity to each other.

Code # 2: Understanding Hypernerms and Hyponyms

from nltk.corpus import wordnet

syn = wordnet.synsets ( `hello` ) [ 0 ]

 

print ( " Synset name: " , syn.name ())

 

print ( "Syns et abstract term: " , syn.hypernyms ())

  

print ( "Synset specific term: "

syn.hypernyms () [ 0 ]. hyponyms ())

  
syn.root_hypernyms ()

 

print ( "Synset root hypernerm: " , syn.root_hypernyms ())

Exit :

 Synset name: hello.n.01 Synset abstract term: [Synset (`greeting.n.01`)] Synset specific term: [Synset (` calling_card.n.02` ), Synset (`good_afternoon.n.01`), S ynset (`good_morning.n.01`), Synset (` hail.n.03`), Synset (`hello.n.01`), Synset (` pax.n.01`), Synset (`reception.n .01`), Synset (`regard.n.03`), Synset (` salute.n.02`), Synset (`salute.n.03`), Synset (` welcome.n.02`), Synset (`well-wishing.n.01`)] Synset root hypernerm: [Synset (` entity.n.01`)] 

Code # 3: Part of Speech (POS) in Synset.

syncode> = wordnet.synsets ( `hello` ) [ 0 ]

print ( "Syn tag:" , syn.pos ())

  

syncode> = wordnet.synsets ( ` doing` ) [ 0 ]

print ( "Syn tag:" , syn.pos ())

  

syn = wordnet.synsets ( `beautiful` ) [ 0 ]

print ( "Syn tag:" , syn.pos ())

 

syncode> = wordnet.s ynsets ( `quickly` ) [ 0 ]

print ( " Syn tag: " , syn.pos ())

Exit :

 Syn tag: n Syn tag: v Syn tag: a Syn tag: r