Suppose I have two synsets synset(car.n.01') and synset('bank.n.01') and If I want to find the distance between these two synset in wordnet hierarchy then How can I do it using nltk?
I searched on internet but I am getting similarity algorithms like lin,resnik,jcn etc which are not solution for my question.
Please help me to solve this problem.
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.
you will find more distance processing in that file
来源:https://stackoverflow.com/questions/22031968/how-to-find-distance-between-two-synset-using-python-nltk-in-wordnet-hierarchy