You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These functions in wordnet's Synset() object could be unified:
hypernym_paths
min_depth
max_depth
root_hypernyms
The while loops / recursion achieve the same purpose of reaching the root hypernyms, while doing so, the min and max depth should be logged and so should the hypernym paths.
We can derive the other three attributes given the hypernym_paths, e.g.
definit_hypernym_paths(self):
""" Get the path(s) from this synset to the root, where each path is a list of the synset nodes traversed on the way to the root. :return: A list of lists, where each list gives the node sequence connecting the initial ``Synset`` node and a root node. """self._hyperpaths= []
hypernyms=self.hypernyms() +self.instance_hypernyms()
iflen(hypernyms) ==0:
paths= [[self]]
forhypernyminhypernyms:
forancestor_listinhypernym.hypernym_paths():
ancestor_list.append(self)
self._hyperpaths.append(ancestor_list)
# Compute the path related statistics.self._min_depth=min(len(path) forpathinself._hyperpaths)
self._max_depth=max(len(path) forpathinself._hyperpaths)
# Compute the store the root hypernyms.self._root_hypernyms=list(set([path[0] forpathinself._hyperpaths]))
defhypernym_paths():
returnself._hyperpathsdefmin_depth():
returnself._min_depthdefmax_depth():
returnself._max_depthdefroot_hypernyms():
returnself._root_hypernyms
The text was updated successfully, but these errors were encountered:
These functions in wordnet's
Synset()
object could be unified:The while loops / recursion achieve the same purpose of reaching the root hypernyms, while doing so, the min and max depth should be logged and so should the hypernym paths.
We can derive the other three attributes given the hypernym_paths, e.g.
Something like this:
The text was updated successfully, but these errors were encountered: