(synsets, root=None)
return nodes
Create a DAG that only contains synsets and all of their ancestors.

  By construction, the leaves of this graph are all and only the Synsets in the
  synsets list. The internal nodes of the graph are all and only the ancestors
  of synsets. All children/parent pointers of the graph nodes are restricted to
  only lead to other nodes that also belong to the ancestor graph. Finally,
  appropriate collapsing is performed so that no node has only one child (since
  it's not possible to create an episode from that node).

  Args:
    synsets: A list of Synsets
    root: Optionally, a Synset. If provided, it imposes a restriction on which
      ancestors of the given synsets will be included in the sampling graph.
      Specifically, an ancestor of a Synset in synsets in will be included only
      if it is the root or a descendent of the root. This is useful when
      creating the validation and test sub- graphs, where we want the designated
      root to indeed have to upward connections in the corresponding subgraph.

  Returns:
    A set of the Synsets of the DAG.
Create a DAG that only contains synsets and all of their ancestors.
Create a DAG that only contains synsets and all of their ancestors .
def create_sampling_graph(synsets, root=None):
  """Create a DAG that only contains synsets and all of their ancestors.

  By construction, the leaves of this graph are all and only the Synsets in the
  synsets list. The internal nodes of the graph are all and only the ancestors
  of synsets. All children/parent pointers of the graph nodes are restricted to
  only lead to other nodes that also belong to the ancestor graph. Finally,
  appropriate collapsing is performed so that no node has only one child (since
  it's not possible to create an episode from that node).

  Args:
    synsets: A list of Synsets
    root: Optionally, a Synset. If provided, it imposes a restriction on which
      ancestors of the given synsets will be included in the sampling graph.
      Specifically, an ancestor of a Synset in synsets in will be included only
      if it is the root or a descendent of the root. This is useful when
      creating the validation and test sub- graphs, where we want the designated
      root to indeed have to upward connections in the corresponding subgraph.

  Returns:
    A set of the Synsets of the DAG.
  """
  # Get the set of Synsets containing all and only the ancestors of synsets.
  nodes = get_ancestors(synsets)

  if root is not None:
    # Remove from the ancestors nodes that aren't the root or descendents of it.
    nodes_to_remove = [
        n for n in nodes if not (root == n or is_descendent(n, root))
    ]
    nodes = nodes - set(nodes_to_remove)

  # The total nodes of the graph are the nodes in synsets, and their ancestors.
  nodes = nodes | set(synsets)

  # Remove all connections from nodes of the graph to other nodes.
  isolate_graph(nodes)

  # Remove all nodes with only one child and attach that child to their parents.
  nodes = collapse(nodes)
  return nodes
def create_sampling_graph ( synsets , root = None ) : # Get the set of Synsets containing all and only the ancestors of synsets. nodes = get_ancestors ( synsets ) if root is not None : # Remove from the ancestors nodes that aren't the root or descendents of it. nodes_to_remove = [ n for n in nodes if not ( root == n or is_descendent ( n , root ) ) ] nodes = nodes - set ( nodes_to_remove ) # The total nodes of the graph are the nodes in synsets, and their ancestors. nodes = nodes | set ( synsets ) # Remove all connections from nodes of the graph to other nodes. isolate_graph ( nodes ) # Remove all nodes with only one child and attach that child to their parents. nodes = collapse ( nodes ) return nodes