Wizard Book


Programming Python, Web, Android

Python: Kamus English Dictionary, Synonyms, Antonyms, Similarity dengan NLTK Wordnet

Kamus Inggris, Sinonim, Antonim, Definisi, Contoh, Similarity dengan Python NLTK Wordnet

from nltk.corpus import wordnet
syns = wordnet.synsets("program")
print(syns[0].name())
#plan.n.01
print(syns[0].lemmas()[0].name())
#plan
print(syns[0].definition())
#a series of steps to be carried out or goals to be accomplished
print(syns[0].examples())
#['they drew up a six-step plan', 'they discussed plans for a new bond issue']

synonyms = []
antonyms = []

for syn in wordnet.synsets("good"):
    for l in syn.lemmas():
        synonyms.append(l.name())
        if l.antonyms():
            antonyms.append(l.antonyms()[0].name())

print(set(synonyms))
print(set(antonyms))

w1 = wordnet.synset('ship.n.01')
w2 = wordnet.synset('boat.n.01')
print(w1.wup_similarity(w2))
#0.9090909090909091

w1 = wordnet.synset('ship.n.01')
w2 = wordnet.synset('car.n.01')
print(w1.wup_similarity(w2))
#0.6956521739130435

w1 = wordnet.synset('ship.n.01')
w2 = wordnet.synset('cat.n.01')
print(w1.wup_similarity(w2))
#0.38095238095238093

email : contohprogram.com@gmail.com
WA : +6289671400363