In [1]:
# WordNet

from nltk.corpus import wordnet

# Synset
syns = wordnet.synsets('good')

# Print only the Word
print(syns[0].lemmas()[0].name())
print('\n')

# Returns definition of word from Dicitionary
print(syns[0].definition())
print('\n')

# Returns Examples for words meaning
print(syns[0].examples())
print('\n')


# Prints Synonyms and Antonyms
synonyms = []
antonyms = []

for syn in wordnet.synsets('good'):
    for l in syn.lemmas():
        print('l: ',l)
        synonyms.append(l.name())
        if l.antonyms():
            antonyms.append(l.antonyms()[0].name())
            
print(set(synonyms))
print('\n')
print(set(antonyms))
print('\n')


# Compare Symmantic Similarity of two words
w1 = wordnet.synset('ship.n.01')
w2 = wordnet.synset('boat.n.01')
print(w1.wup_similarity(w2))
print('\n')

w1 = wordnet.synset('boat.n.01')
w2 = wordnet.synset('cactus.n.01')
print(w1.wup_similarity(w2))
print('\n')

w1 = wordnet.synset('car.n.01')
w2 = wordnet.synset('cycle.n.01')
print(w1.wup_similarity(w2))


good


benefit


['for your own good', "what's the good of worrying?"]


l:  Lemma('good.n.01.good')
l:  Lemma('good.n.02.good')
l:  Lemma('good.n.02.goodness')
l:  Lemma('good.n.03.good')
l:  Lemma('good.n.03.goodness')
l:  Lemma('commodity.n.01.commodity')
l:  Lemma('commodity.n.01.trade_good')
l:  Lemma('commodity.n.01.good')
l:  Lemma('good.a.01.good')
l:  Lemma('full.s.06.full')
l:  Lemma('full.s.06.good')
l:  Lemma('good.a.03.good')
l:  Lemma('estimable.s.02.estimable')
l:  Lemma('estimable.s.02.good')
l:  Lemma('estimable.s.02.honorable')
l:  Lemma('estimable.s.02.respectable')
l:  Lemma('beneficial.s.01.beneficial')
l:  Lemma('beneficial.s.01.good')
l:  Lemma('good.s.06.good')
l:  Lemma('good.s.07.good')
l:  Lemma('good.s.07.just')
l:  Lemma('good.s.07.upright')
l:  Lemma('adept.s.01.adept')
l:  Lemma('adept.s.01.expert')
l:  Lemma('adept.s.01.good')
l:  Lemma('adept.s.01.practiced')
l:  Lemma('adept.s.01.proficient')
l:  Lemma('adept.s.01.skillful')
l:  Lemma('adept.s.01.skilful')
l:  Lemma('good.s.09.good')
l:  Lemma('dear.s.02.dear')
l:  Lemma('dear.s.02.good')
l:  Lemma('dear.s.02.near')
l:  Lemma('dependable.s.04.dependable')
l:  Lemma('dependable.s.04.good')
l:  Lemma('dependable.s.04.safe')
l:  Lemma('dependable.s.04.secure')
l:  Lemma('good.s.12.good')
l:  Lemma('good.s.12.right')
l:  Lemma('good.s.12.ripe')
l:  Lemma('good.s.13.good')
l:  Lemma('good.s.13.well')
l:  Lemma('effective.s.04.effective')
l:  Lemma('effective.s.04.good')
l:  Lemma('effective.s.04.in_effect')
l:  Lemma('effective.s.04.in_force')
l:  Lemma('good.s.15.good')
l:  Lemma('good.s.16.good')
l:  Lemma('good.s.16.serious')
l:  Lemma('good.s.17.good')
l:  Lemma('good.s.17.sound')
l:  Lemma('good.s.18.good')
l:  Lemma('good.s.18.salutary')
l:  Lemma('good.s.19.good')
l:  Lemma('good.s.19.honest')
l:  Lemma('good.s.20.good')
l:  Lemma('good.s.20.undecomposed')
l:  Lemma('good.s.20.unspoiled')
l:  Lemma('good.s.20.unspoilt')
l:  Lemma('good.s.21.good')
l:  Lemma('well.r.01.well')
l:  Lemma('well.r.01.good')
l:  Lemma('thoroughly.r.02.thoroughly')
l:  Lemma('thoroughly.r.02.soundly')
l:  Lemma('thoroughly.r.02.good')
{'salutary', 'estimable', 'in_effect', 'honorable', 'honest', 'undecomposed', 'soundly', 'commodity', 'beneficial', 'trade_good', 'skillful', 'upright', 'secure', 'serious', 'expert', 'right', 'goodness', 'ripe', 'dear', 'skilful', 'unspoiled', 'in_force', 'well', 'just', 'thoroughly', 'practiced', 'near', 'full', 'dependable', 'sound', 'unspoilt', 'proficient', 'safe', 'good', 'respectable', 'effective', 'adept'}


{'evil', 'evilness', 'badness', 'bad', 'ill'}


0.9090909090909091


0.38095238095238093


0.125

In [ ]: