In [8]:
from nltk.corpus import wordnet as wn
from itertools import product
wordx, wordy = "phone","tablet"
sem1, sem2 = wn.synsets(wordx), wn.synsets(wordy)
In [9]:
sem1
Out[9]:
In [10]:
sem2
Out[10]:
In [11]:
prod = list(product(*[sem1,sem2]))
In [12]:
prod[1][0].wup_similarity(prod[1][1])
Out[12]:
In [13]:
maxscore = 0.0
for i,j in prod:
score = i.wup_similarity(j) # Wu-Palmer Similarity
if score is not None:
if maxscore < score:
maxscore = score
In [15]:
print("Similarity between phone and tablet is : " + str(maxscore))
In [3]:
import nltk
text = nltk.Text(word.lower() for word in nltk.corpus.brown.words())
text.similar('woman')
In [4]:
similar_words = text._word_context_index.similar_words('woman')
print(' '.join(similar_words))
In [5]:
text._word_context_index.common_contexts(['cat', 'dog'])
Out[5]:
In [6]:
len(text._word_context_index.common_contexts(['brown', 'red']))
Out[6]:
In [7]:
text
Out[7]:
In [17]:
x = {}
x["hi"] = "there"
In [18]:
x
Out[18]:
In [20]:
"there" in x
Out[20]:
In [ ]: