list1 と list2 のアイテム間の synset 類似度を計算する必要があります。list1 の単語の synset 類似度の最大値のみを保持したいと考えています。どうすればいいですか?出力を
apple.n.01, pear.n.01: 0.909090909091
honey.n.01, pear.n.01: 0.333333333333
マイコード
>>> from nltk.corpus import wordnet
>>> import itertools as IT
>>> list1 = ["apple", "honey"]
>>> list2 = ["pear", "shell", "movie", "fire", "tree", "candle"]
>>> for word1, word2 in IT.product(list1, list2):
wordFromList1 = wordnet.synsets(word1)[0]
wordFromList2 = wordnet.synsets(word2)[0]
s = wordFromList1.wup_similarity(wordFromList2)
print('{w1}, {w2}: {s}'.format(w1 = wordFromList1.name,w2 = wordFromList2.name,s = wordFromList1.wup_similarity(wordFromList2)))
apple.n.01, pear.n.01: 0.909090909091
apple.n.01, shell.n.01: 0.4
apple.n.01, movie.n.01: 0.421052631579
apple.n.01, fire.n.01: 0.142857142857
apple.n.01, tree.n.01: 0.380952380952
apple.n.01, candle.n.01: 0.380952380952
honey.n.01, pear.n.01: 0.333333333333
honey.n.01, shell.n.01: 0.210526315789
honey.n.01, movie.n.01: 0.222222222222
honey.n.01, fire.n.01: 0.125
honey.n.01, tree.n.01: 0.2
honey.n.01, candle.n.01: 0.2