I want to input a string, tokenize it, and compare each word with a specific word (in this code, the word is 'play'). I have the code
from nltk.tokenize import word_tokenize
txt = "bat ball cocaine golf football cake leg hand me you her she he dog cat drug"
x = word_tokenize(txt)
from nltk.corpus import wordnet
for i in range (10):
syn = wordnet.synsets(x[i])[0]
print ("Synset name : ", syn.name())
w1 = wordnet.synset('play.n.01')
w2 = wordnet.synset(syn)
print(w1.wup_similarity(w2))
i = i +1
This gives an error:
AttributeError Traceback (most recent call last)
<ipython-input-127-a30645977ba6> in <module>()
13
14 w1 = wordnet.synset('play.n.01')
---> 15 w2 = wordnet.synset(syn)
16 print(w1.wup_similarity(w2))
17 i = i +1
help