我必须计算 list1 和 list2 项目之间的同义词集相似度。我只想保留 list1 中单词的最大同义词相似度值。我该怎么做呢?我希望我的输出是
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