我正在尝试在文本文件中查找单词的相似性。我已经在下面的代码中附加了我从文本文件中读取的内容,并将内容分为两个列表,但是现在我想将列表1中的单词与列表2中的单词进行比较。
file = open('M:\ThirdYear\CE314\Assignment2\sim_data\Assignment_Additional.txt', 'r')
word1 = []
word2 = []
split = [line.strip() for line in file]
count = 0
for line in split:
if count == (len(split) - 1):
break
else:
word1.append(line.split('\t')[0])
word2.append(line.split('\t')[1])
count = count + 1
print(word1)
print(word2)
for x, y in zip(word1, word2):
w1 = wordnet.synset(x + '.n.1')
w2 = wordnet.synset(y + '.n.1')
print(w1.path_similarity(w2))
我想遍历两个列表并打印它们的path_similarity,但仅当它们遵守规则wordnet.synset(x +'.n.1')时,这意味着我想要的任何不具有'.n.1'的单词忽略和跳过,但我不完全确定如何在python中进行此检查