我收到此错误,一切都很好,我搜索了很多但没有找到任何解决方案
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'