(node_representations)
return graph
Returns a set of Synset nodes from JSON-serializable representation.

  See the documentation of `export_graph` for a description of the format
  of that representation.

  Args:
    node_representations: A list of dictionaries, each representing a Synset.

  Returns:
    A set of Synset objects (nodes), representing a graph.
Returns a set of Synset nodes from JSON-serializable representation.
Returns a set of Synset nodes from JSON - serializable representation .
def import_graph(node_representations):
  """Returns a set of Synset nodes from JSON-serializable representation.

  See the documentation of `export_graph` for a description of the format
  of that representation.

  Args:
    node_representations: A list of dictionaries, each representing a Synset.

  Returns:
    A set of Synset objects (nodes), representing a graph.
  """
  graph = set()
  # Build one Synset node for each WordNet ID, and keep a mapping.
  # `children` and `parents` are initialized with empty sets.
  wn_id_to_node = dict()
  for node_repr in node_representations:
    wn_id = node_repr['wn_id']
    words = node_repr['words']
    if wn_id in wn_id_to_node:
      raise ValueError('Duplicate Word ID (%s, %s) in the imported graph.' %
                       (wn_id, words))
    node = Synset(wn_id=wn_id, words=words, children=set(), parents=set())
    wn_id_to_node[wn_id] = node

  # Fill in the `children` and `parents` with the Synset objects.
  for node_repr in node_representations:
    wn_id = node_repr['wn_id']
    node = wn_id_to_node[wn_id]
    children_ids = node_repr['children_ids']
    node.children.update(wn_id_to_node[child_id] for child_id in children_ids)
    parents_ids = node_repr['parents_ids']
    node.parents.update(wn_id_to_node[parent_id] for parent_id in parents_ids)
    graph.add(node)

  return graph
def import_graph ( node_representations ) : graph = set ( ) # Build one Synset node for each WordNet ID, and keep a mapping. # `children` and `parents` are initialized with empty sets. wn_id_to_node = dict ( ) for node_repr in node_representations : wn_id = node_repr [ 'wn_id' ] words = node_repr [ 'words' ] if wn_id in wn_id_to_node : raise ValueError ( 'Duplicate Word ID (%s, %s) in the imported graph.' % ( wn_id , words ) ) node = Synset ( wn_id = wn_id , words = words , children = set ( ) , parents = set ( ) ) wn_id_to_node [ wn_id ] = node # Fill in the `children` and `parents` with the Synset objects. for node_repr in node_representations : wn_id = node_repr [ 'wn_id' ] node = wn_id_to_node [ wn_id ] children_ids = node_repr [ 'children_ids' ] node . children . update ( wn_id_to_node [ child_id ] for child_id in children_ids ) parents_ids = node_repr [ 'parents_ids' ] node . parents . update ( wn_id_to_node [ parent_id ] for parent_id in parents_ids ) graph . add ( node ) return graph