A = 'car.n.01'
B = 'automobile.v.01'
C = 'automobile.n.01'
wn.synset(A).path_similarity(wn.synset(B))
wn.synset(B).path_similarity(wn.synset(A))
wn.synset(A).path_similarity(wn.synset(C)) # is 1
wn.synset(C).path_similarity(wn.synset(A)) # is also 1
>>> from nltk.corpus import wordnet as wn
>>> x = wn.synset('car.n.01')
>>> y = wn.synset('automobile.v.01')
# When you NEVER want a non-zero value, since going to
# the *ROOT* will always get you some sort of distance
# from synset x to synset y
>>> max(wn.path_similarity(x,y), wn.path_similarity(y,x))
# when you can allow None in synset similarity comparison
>>> min(wn.path_similarity(x,y), wn.path_similarity(y,x))
我不认为这是wordnet本身的缺陷。在您的例子中,automobile被指定为动词,car被指定为名词,因此您需要查看synset以查看图形的外观,并确定网络是否正确标记。在
从技术上讲,如果没有虚拟根,}两个synsets都不会相互链接:
car
和{现在,让我们仔细看看虚拟根问题。首先,NLTK中有一个简洁的函数,它表示synset是否需要一个伪根:
^{pr2}$接下来,当您查看
path_similarity
代码(http://nltk.googlecode.com/svn-/trunk/doc/api/nltk.corpus.reader.wordnet-pysrc.html#Synset.path_similarity)时,您可以看到:因此对于},当您尝试{}时,它将始终是{},因为{}是{}:
automobile
synset,当您尝试y.path_similarity(x)
时,该参数simulate_root=simulate_root and self._needs_root()
将始终是{现在当},反之亦然:
path_similarity()
向下传递到shortest_path_distance()
(https://nltk.googlecode.com/svn/trunk/doc/api/nltk.corpus.reader.wordnet-pysrc.html#Synset.shortest_path_distance)然后再传递到hypernym_distances()
时,它将尝试调用一个超链接词列表来检查它们的距离,如果没有simulate_root = True
,automobile
语法集将不会连接到{所以理论上,右
path_similarity
是0/None,但是由于simulate_root=simulate_root and self._needs_root()
参数NLTK的API中的
nltk.corpus.wordnet.path_similarity()
不是可交换的。但是代码也没有错误/错误,因为通过根进行的任何synset距离的比较都将持续很远,因为伪
*ROOT*
的位置永远不会改变,所以最好的做法是这样做来计算路径相似性:相关问题 更多 >
编程相关推荐