nlp13. WordNet in Python NLTK

WordNet provides a dictionary-like structure of Synset objects.

We can give it a string and optionally part of speech. If we don’t give part of speech, it will return all the matching synsets of different parts of speech.

We use the definitions method, as we iterate over the objects returned.


# nlp13.py
from __future__ import print_function, division
from nltk.corpus import wordnet
arr = "t-->"
A = wordnet.synsets('love')
for s in A:
print(s)
print(arr+s.definition())

# Synset('love.n.01')
# -->a strong positive emotion of regard and affection
# Synset('love.n.02')
# -->any object of warm affection or devotion;
# Synset('beloved.n.01')
# -->a beloved person; used as terms of endearment
# Synset('love.n.04')
# -->a deep feeling of sexual desire and attraction
# Synset('love.n.05')
# -->a score of zero in tennis or squash
# Synset('sexual_love.n.02')
# -->sexual activities (often including sexual intercourse)
# between two people
# Synset('love.v.01')
# -->have a great affection or liking for
# Synset('love.v.02')
# -->get pleasure from
# Synset('love.v.03')
# -->be enamored or in love with
# Synset('sleep_together.v.01')
# -->have sexual intercourse with

Leave a Reply

Your email address will not be published. Required fields are marked *