Commit e8ac4716 by Steven Xu

removed _lcs_by_depth(), see https://github.com/nltk/nltk/pull/662

parent 24e257a6
...@@ -1815,65 +1815,6 @@ def lin_similarity(synset1, synset2, ic, verbose=False): ...@@ -1815,65 +1815,6 @@ def lin_similarity(synset1, synset2, ic, verbose=False):
lin_similarity.__doc__ = Synset.lin_similarity.__doc__ lin_similarity.__doc__ = Synset.lin_similarity.__doc__
def _lcs_by_depth(synset1, synset2, verbose=False):
"""
Finds the least common subsumer of two synsets in a WordNet taxonomy,
where the least common subsumer is defined as the ancestor node common
to both input synsets whose shortest path to the root node is the longest.
:type synset1: Synset
:param synset1: First input synset.
:type synset2: Synset
:param synset2: Second input synset.
:return: The ancestor synset common to both input synsets which is also the
LCS.
"""
subsumer = None
max_min_path_length = -1
subsumers = synset1.common_hypernyms(synset2)
if verbose:
print("> Subsumers1:", subsumers)
# Eliminate those synsets which are ancestors of other synsets in the
# set of subsumers.
eliminated = set()
hypernym_relation = lambda s: s.hypernyms() + s.instance_hypernyms()
for s1 in subsumers:
for s2 in subsumers:
if s2 in s1.closure(hypernym_relation):
eliminated.add(s2)
if verbose:
print("> Eliminated:", eliminated)
subsumers = [s for s in subsumers if s not in eliminated]
if verbose:
print("> Subsumers2:", subsumers)
# Calculate the length of the shortest path to the root for each
# subsumer. Select the subsumer with the longest of these.
for candidate in subsumers:
paths_to_root = candidate.hypernym_paths()
min_path_length = -1
for path in paths_to_root:
if min_path_length < 0 or len(path) < min_path_length:
min_path_length = len(path)
if min_path_length > max_min_path_length:
max_min_path_length = min_path_length
subsumer = candidate
if verbose:
print("> LCS Subsumer by depth:", subsumer)
return subsumer
def _lcs_ic(synset1, synset2, ic, verbose=False): def _lcs_ic(synset1, synset2, ic, verbose=False):
""" """
Get the information content of the least common subsumer that has Get the information content of the least common subsumer that has
......
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