Tuesday, May 26, 2015

nlp14. WordNet Examples and Hyponyms in Python NLTK

Among the methods of WordNet are examples and hyponyms.


examples() find sentences where the word is used, while hyponyms() finds the tree structure of similar words.

# nlp14.py
from __future__ import print_function, division
from nltk.corpus import wordnet
arr = "\t-->"
A = wordnet.synset('love.n.01')
for ex in A.examples():
    print('ex:'+ex)
for h in A.hyponyms():
    print(arr,h)

# ex:his love for his work
# ex:children need a lot of love
#        --> Synset('agape.n.01')
#        --> Synset('agape.n.02')
#        --> Synset('amorousness.n.01')
#        --> Synset('ardor.n.02')
#        --> Synset('benevolence.n.01')
#        --> Synset('devotion.n.01')
#        --> Synset('filial_love.n.01')
#        --> Synset('heartstrings.n.01')
#        --> Synset('lovingness.n.01')
#        --> Synset('loyalty.n.02')
#        --> Synset('puppy_love.n.01')
#        --> Synset('worship.n.02')

No comments:

Post a Comment