(synset)
return ancestors
Create a set consisting of all and only the ancestors of synset.

  Args:
    synset: A Synset.

  Returns:
    ancestors: A set of Synsets
Create a set consisting of all and only the ancestors of synset.
Create a set consisting of all and only the ancestors of synset .
def get_node_ancestors(synset):
  """Create a set consisting of all and only the ancestors of synset.

  Args:
    synset: A Synset.

  Returns:
    ancestors: A set of Synsets
  """
  ancestors = set()
  # In the following line, synset.parents already is a set but we create a copy
  # of it instead of using synset.parents directly as later we are 'popping'
  # elements from this set, which would otherwise result to permanently removing
  # parents of synset which is undesirable.
  to_visit = set(synset.parents)
  visited = set()
  while to_visit:
    ancestor = to_visit.pop()
    ancestors.add(ancestor)
    visited.add(ancestor)
    # Same as in the comment above, we create a copy of ancestor.parents
    to_visit = to_visit | set(ancestor.parents) - visited
  return ancestors
def get_node_ancestors ( synset ) : ancestors = set ( ) # In the following line, synset.parents already is a set but we create a copy # of it instead of using synset.parents directly as later we are 'popping' # elements from this set, which would otherwise result to permanently removing # parents of synset which is undesirable. to_visit = set ( synset . parents ) visited = set ( ) while to_visit : ancestor = to_visit . pop ( ) ancestors . add ( ancestor ) visited . add ( ancestor ) # Same as in the comment above, we create a copy of ancestor.parents to_visit = to_visit | set ( ancestor . parents ) - visited return ancestors