(start, end=None)
return paths
Creates a list of paths that go from start either to end or to a root.

  There may be more than one such paths, since the structure we are traversing
  is a DAG (not strictly a tree). Every path is represented as a list of Synsets
  whose first elements is a Synset without parents and whose last element is s.

  Args:
    start: A Synset.
    end: A Synset. If not provided, the end point will be the first node that is
      encountered starting from start that does not have parents.

  Returns:
    A list of lists, containing all paths as described above.
Creates a list of paths that go from start either to end or to a root.
Creates a list of paths that go from start either to end or to a root .
def get_upward_paths_from(start, end=None):
  """Creates a list of paths that go from start either to end or to a root.

  There may be more than one such paths, since the structure we are traversing
  is a DAG (not strictly a tree). Every path is represented as a list of Synsets
  whose first elements is a Synset without parents and whose last element is s.

  Args:
    start: A Synset.
    end: A Synset. If not provided, the end point will be the first node that is
      encountered starting from start that does not have parents.

  Returns:
    A list of lists, containing all paths as described above.
  """

  def is_end_node(n):
    return (end is not None and n == end) or (end is None and not n.parents)

  if end is not None and not start.parents:
    # There are no upwards paths from start in which the specified end can be.
    return []

  if is_end_node(start):
    return [[start]]

  # If we got here, we haven't yet reached the target node and there are upward
  # paths to explore.
  parents = start.parents

  # A list of all paths from start to end (or to a root node).
  paths = []

  # Case where end is a direct parent of start:
  for p in parents:
    if is_end_node(p):
      # Found one path from start to end.
      paths.append([start, p])

    else:
      # Get a list of lists corresponding to paths between p and end.
      p_to_end_paths = get_upward_paths_from(p, end=end)
      if not p_to_end_paths:  # end not an ancestor of p.
        continue
      start_to_end_paths = [[start] + p_path for p_path in p_to_end_paths]
      paths.extend(start_to_end_paths)
  return paths
def get_upward_paths_from ( start , end = None ) : def is_end_node ( n ) : return ( end is not None and n == end ) or ( end is None and not n . parents ) if end is not None and not start . parents : # There are no upwards paths from start in which the specified end can be. return [ ] if is_end_node ( start ) : return [ [ start ] ] # If we got here, we haven't yet reached the target node and there are upward # paths to explore. parents = start . parents # A list of all paths from start to end (or to a root node). paths = [ ] # Case where end is a direct parent of start: for p in parents : if is_end_node ( p ) : # Found one path from start to end. paths . append ( [ start , p ] ) else : # Get a list of lists corresponding to paths between p and end. p_to_end_paths = get_upward_paths_from ( p , end = end ) if not p_to_end_paths : # end not an ancestor of p. continue start_to_end_paths = [ [ start ] + p_path for p_path in p_to_end_paths ] paths . extend ( start_to_end_paths ) return paths