python - NLTK wordnet 计算两个列表中单词的路径相似度
问题描述
我正在尝试查找文本文件中单词的相似性。我附上了下面的代码,我从文本文件中读取并将内容分成两个列表,但现在我想将列表 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 中进行此检查
解决方案
推荐阅读
- reactjs - 反应:在提交时获取按钮的形式
- c++ - 为类模板中的成员函数定义单个模板,同时在成员函数中使用两个模板
- c# - 如何使用c#编辑excel行值
- firebase - Vuejs - Firebase/firestore 垃圾邮件网络请求
- kubernetes - 使用 REST_API 进行 Openshift 监控
- c# - 仅在 wpf 中的顶级项目之后将分隔符添加到 TreeView
- django - 我的第一个 django 应用程序 - 如何导入模板?
- git - Git:将两个分支之间的差异直接应用到master
- javascript - 在谷歌电子表格 GAS 的所需列中找到最后一个单元格
- vue.js - 如何删除 Vuex 状态数据