Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import nltk
- __author__ = "Sreejith Sreekumar"
- __email__ = "sreekumar.s@husky.neu.edu"
- __version__ = "0.0.1"
- nltk.download('wordnet')
- from nltk.corpus import wordnet
- #wordnet.synsets('dog')
- def calc_sim(vectors, words):
- num = np.dot(vectors[words[0]], vectors[words[1]])
- den = (np.linalg.norm(vectors[words[0]]) * np.linalg.norm(vectors[words[1]]))
- return (num/den)
- def alg1(w1, w2):
- wordFromList1 = wordnet.synsets(w1)
- wordFromList2 = wordnet.synsets(w2)
- res = []
- if wordFromList1 and wordFromList2: #Thanks to @alexis' note
- s = wordFromList1[0].wup_similarity(wordFromList2[0])
- res.append(s)
- else:
- res = 0.5
- return res
- alg1('planet','moon')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement