Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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']
- ##The lemmas will be synonyms,
- ##and then you can use .antonyms to find the antonyms to the lemmas
- 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))
- #compare the similarity of two words and their tenses
- #we use Wu and Palmer method for semantic related-ness
- w1 = wordnet.synset('ship.n.01')
- w2 = wordnet.synset('boat.n.01')
- print(w1.wup_similarity(w2))
- w1 = wordnet.synset('ship.n.01')
- w2 = wordnet.synset('car.n.01')
- print(w1.wup_similarity(w2))
- w1 = wordnet.synset('ship.n.01')
- w2 = wordnet.synset('cat.n.01')
- print(w1.wup_similarity(w2))
Add Comment
Please, Sign In to add comment