How to find distance between two synset using python nltk in wordnet hierarchy?

孤人 提交于 2019-12-02 08:29:33
axiom

From this

Path similarity, wup_similarity and lch_similarity, all of these should work since they are based on the distance between two synsets in the Wordnet hierarchy.

dog = wn.synset('dog.n.01')
cat = wn.synset('cat.n.01')

dog.path_similarity(cat)

dog.lch_similarity(cat)

dog.wup_similarity(cat)


From the same link, (relevant portions in bold)

synset1.path_similarity(synset2):

Return a score denoting how similar two word senses are, based on the shortest path that connects the senses in the is-a (hypernym/hypnoym) taxonomy. The score is in the range 0 to 1, except in those cases where a path cannot be found (will only be true for verbs as there are many distinct verb taxonomies), in which case -1 is returned. A score of 1 represents identity i.e. comparing a sense with itself will return 1.


synset1.lch_similarity(synset2), Leacock-Chodorow Similarity:

Return a score denoting how similar two word senses are, based on the shortest path that connects the senses (as above) and the maximum depth of the taxonomy in which the senses occur. The relationship is given as -log(p/2d) where p is the shortest path length and d the taxonomy depth.


synset1.wup_similarity(synset2), Wu-Palmer Similarity:

Return a score denoting how similar two word senses are, based on the depth of the two senses in the taxonomy and that of their Least Common Subsumer (most specific ancestor node). Note that at this time the scores given do not always agree with those given by Pedersen's Perl implementation of Wordnet Similarity.

in addition you could have a look on the chatterbot implementation.

"chatterbot comparison class"

you will find more distance processing in that file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!