Commit ec30ef82 by Steven Bethard

Issue #284. Use instance hypernyms in all similarity calculations

svn/trunk@8765
parent a001e38f
......@@ -417,7 +417,7 @@ class Synset(_WordNetObject):
"""
paths = []
hypernyms = self.hypernyms()
hypernyms = self.hypernyms() + self.instance_hypernyms()
if len(hypernyms) == 0:
paths = [[self]]
......@@ -1601,7 +1601,7 @@ def _lcs_by_depth(synset1, synset2, verbose=False):
# set of subsumers.
eliminated = set()
hypernym_relation = lambda s: s.hypernyms()
hypernym_relation = lambda s: s.hypernyms() + s.instance_hypernyms()
for s1 in subsumers:
for s2 in subsumers:
if s2 in s1.closure(hypernym_relation):
......
......@@ -502,3 +502,18 @@ Bug 482: Some nouns not being lemmatised by WordNetLemmatizer().lemmatize
'egg'
>>> WordNetLemmatizer().lemmatize("legs", pos="n")
'leg'
Bug 284: instance hypernyms not used in similarity calculations
>>> wn.synset('john.n.02').lch_similarity(wn.synset('dog.n.01'))
1.335...
>>> wn.synset('john.n.02').wup_similarity(wn.synset('dog.n.01'))
0.571...
>>> wn.synset('john.n.02').res_similarity(wn.synset('dog.n.01'), brown_ic)
2.224...
>>> wn.synset('john.n.02').jcn_similarity(wn.synset('dog.n.01'), brown_ic)
0.075...
>>> wn.synset('john.n.02').lin_similarity(wn.synset('dog.n.01'), brown_ic)
0.252...
>>> wn.synset('john.n.02').hypernym_paths()
[[Synset('entity.n.01'), ..., Synset('john.n.02')]]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment