Guest User

Untitled

a guest
Mar 19th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. from nltk.corpus import wordnet
  2.  
  3. syns = wordnet.synsets("program")
  4. print(syns[0].name())
  5. #plan.n.01
  6. print(syns[0].lemmas()[0].name())
  7. #plan
  8. print(syns[0].definition())
  9. #a series of steps to be carried out or goals to be accomplished
  10. print(syns[0].examples())
  11. #['they drew up a six-step plan', 'they discussed plans for a new bond issue']
  12.  
  13.  
  14. ##The lemmas will be synonyms,
  15. ##and then you can use .antonyms to find the antonyms to the lemmas
  16.  
  17. synonyms = []
  18. antonyms = []
  19.  
  20. for syn in wordnet.synsets("good"):
  21. for l in syn.lemmas():
  22. synonyms.append(l.name())
  23. if l.antonyms():
  24. antonyms.append(l.antonyms()[0].name())
  25.  
  26. print(set(synonyms))
  27. print(set(antonyms))
  28.  
  29. #compare the similarity of two words and their tenses
  30. #we use Wu and Palmer method for semantic related-ness
  31.  
  32. w1 = wordnet.synset('ship.n.01')
  33. w2 = wordnet.synset('boat.n.01')
  34. print(w1.wup_similarity(w2))
  35.  
  36. w1 = wordnet.synset('ship.n.01')
  37. w2 = wordnet.synset('car.n.01')
  38. print(w1.wup_similarity(w2))
  39.  
  40. w1 = wordnet.synset('ship.n.01')
  41. w2 = wordnet.synset('cat.n.01')
  42. print(w1.wup_similarity(w2))
Add Comment
Please, Sign In to add comment