(nodes, root_wn_id=None)
return set(copy.values()), root_copy
Create a set of Synsets that are copies of the Synsets in nodes.

  A new Synset is created for each Synset of nodes and then the
  children/parent relationships of the new Synsets are set to mirror the
  corresponding ones in the Synsets of nodes.

  This assumes that nodes is an 'isolated' graph: all parents and
  children of nodes of nodes also belong to the graph.

  Optionally, if the WordNet id of a node is provided, the copy of that node
  will be returned.

  Args:
    nodes: A set of Synsets.
    root_wn_id: The wn_id field of the Synset that is intended to eventually be
      the root of the new graph.

  Returns:
    copy: A set of Synsets of the same size as nodes.
Create a set of Synsets that are copies of the Synsets in nodes.
Create a set of Synsets that are copies of the Synsets in nodes .
def copy_graph(nodes, root_wn_id=None):
  """Create a set of Synsets that are copies of the Synsets in nodes.

  A new Synset is created for each Synset of nodes and then the
  children/parent relationships of the new Synsets are set to mirror the
  corresponding ones in the Synsets of nodes.

  This assumes that nodes is an 'isolated' graph: all parents and
  children of nodes of nodes also belong to the graph.

  Optionally, if the WordNet id of a node is provided, the copy of that node
  will be returned.

  Args:
    nodes: A set of Synsets.
    root_wn_id: The wn_id field of the Synset that is intended to eventually be
      the root of the new graph.

  Returns:
    copy: A set of Synsets of the same size as nodes.
  """
  root_copy = None
  copy = {}  # maps wn_id's to Synsets
  parent_child_tuples = set()

  for s in nodes:
    copy[s.wn_id] = Synset(s.wn_id, s.words, set(), set())
    if root_wn_id is not None and s.wn_id == root_wn_id:
      root_copy = copy[s.wn_id]
    for c in s.children:
      assert c in nodes
      parent_child_tuples.add((s.wn_id, c.wn_id))

  # Add the analogous parent/child relations between nodes in
  # copy as those that existed in nodes
  for parent, child in parent_child_tuples:
    copy[parent].children.add(copy[child])
    copy[child].parents.add(copy[parent])

  return set(copy.values()), root_copy
def copy_graph ( nodes , root_wn_id = None ) : root_copy = None copy = { } # maps wn_id's to Synsets parent_child_tuples = set ( ) for s in nodes : copy [ s . wn_id ] = Synset ( s . wn_id , s . words , set ( ) , set ( ) ) if root_wn_id is not None and s . wn_id == root_wn_id : root_copy = copy [ s . wn_id ] for c in s . children : assert c in nodes parent_child_tuples . add ( ( s . wn_id , c . wn_id ) ) # Add the analogous parent/child relations between nodes in # copy as those that existed in nodes for parent , child in parent_child_tuples : copy [ parent ] . children . add ( copy [ child ] ) copy [ child ] . parents . add ( copy [ parent ] ) return set ( copy . values ( ) ) , root_copy