similarity - Synset' 对象没有属性 'lowest_common_hypernyms'
问题描述
我收到此错误,一切都很好,我搜索了很多但没有找到任何解决方案
def _synset_similarity(s1,s2):
L1 =dict()
L2 =defaultdict(list)
for syn1 in s1:
L1[syn1[0]] =list()
for syn2 in s2:
subsumer = syn1[1].lowest_common_hypernyms(syn2[1], simulate_root=True)[0]
h =subsumer.max_depth() + 1 # as done on NLTK wordnet
syn1_dist_subsumer = syn1[1].shortest_path_distance(subsumer,simulate_root =True)
syn2_dist_subsumer = syn2[1].shortest_path_distance(subsumer,simulate_root =True)
l =syn1_dist_subsumer + syn2_dist_subsumer
f1 = np.exp(-alpha*l)
a = np.exp(beta*h)
b = np.exp(-beta*h)
f2 = (a-b) /(a+b)
sim = f1*f2
L1[syn1[0]].append(sim)
L2[syn2[0]].append(sim)
return L1, L2
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-2321cf4ecea6> in <module>()
66 s2 ='hurricane striked my house severly'
67
---> 68 print('similarity between '+'\"'+s1+'\"'+' and ' +'\"'+ s2+'\"'+ 'is: '+str(getSimilarity(s1,s2)))
1 frames
<ipython-input-5-2321cf4ecea6> in _synset_similarity(s1, s2)
23 for syn2 in s2:
24
---> 25 subsumer = syn1[1].lowest_common_hypernyms(syn2[1], simulate_root=True)[0]
26 h =subsumer.max_depth() + 1 # as done on NLTK wordnet
27 syn1_dist_subsumer = syn1[1].shortest_path_distance(subsumer,simulate_root =True)
AttributeError: 'Synset' object has no attribute 'lowest_common_hypernyms'
解决方案
推荐阅读
- ssl - 如何取消阻止自签名 SSL 证书?
- javascript - 请解释 IIFE 的两种语法
- javascript - v-for 之后的标签中出现意外的字符串
- python - 与相同的单个输入字符串相比,运行时从文件中获取字符串输入非常慢?
- sql - 如何将相同的多个窗口函数组合为一个,并在查询中需要时通过别名调用?
- android - org.gradle.api.tasks.compile.CompileOptions.setBootClasspath(Ljava/lang/String;)V'
- typescript - 如何使用 Jest 模拟 DynamoDb Datamapper 返回的 QueryIterator?
- java - 调整大小过程中的 OpenImaj OutOfMemoryError
- r - Ubuntu 16.04 上的 rhub 编译警告
- amazon-web-services - Terraform ssh 到实例并创建目录