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

  Synset objects are represented by a dictionary containing:
  - their WordNet ID ("wn_id")
  - their text description in words ("words")
  - the WordNet IDs of their children ("children_ids")
  - the WordNet IDs of their parents ("parents_ids")

  The conversion expects that:
  - The WordNet ID is a unique identifier for a Synset object.
  - The parents and children of each Synset in `nodes` is also in `nodes`.

  Args:
    nodes: A set of Synset objects, representing a complete graph.

  Returns:
    A list of dictionaries, following the representation described above.
Returns a JSON-serializable representation of a graph.
Returns a JSON - serializable representation of a graph .
def export_graph(nodes):
  """Returns a JSON-serializable representation of a graph.

  Synset objects are represented by a dictionary containing:
  - their WordNet ID ("wn_id")
  - their text description in words ("words")
  - the WordNet IDs of their children ("children_ids")
  - the WordNet IDs of their parents ("parents_ids")

  The conversion expects that:
  - The WordNet ID is a unique identifier for a Synset object.
  - The parents and children of each Synset in `nodes` is also in `nodes`.

  Args:
    nodes: A set of Synset objects, representing a complete graph.

  Returns:
    A list of dictionaries, following the representation described above.
  """
  node_representations = []
  wn_ids_to_synsets = {synset.wn_id: synset for synset in nodes}
  wn_ids = set(wn_ids_to_synsets.keys())
  if len(wn_ids) != len(nodes):
    raise ValueError('Duplicate WordNet IDs in the same graph')
  # Iterate in lexicographic order over the WordNet IDs
  for wn_id in sorted(wn_ids):
    synset = wn_ids_to_synsets[wn_id]
    children_ids = {child.wn_id for child in synset.children}
    if not children_ids.issubset(wn_ids):
      raise ValueError('Synset has children outside of the graph')
    parents_ids = {parent.wn_id for parent in synset.parents}
    if not parents_ids.issubset(wn_ids):
      raise ValueError('Synset has parents outside of the graph')
    node_repr = dict(
        wn_id=wn_id,
        words=synset.words,
        children_ids=sorted(children_ids),
        parents_ids=sorted(parents_ids))
    node_representations.append(node_repr)
  return node_representations
def export_graph ( nodes ) : node_representations = [ ] wn_ids_to_synsets = { synset . wn_id : synset for synset in nodes } wn_ids = set ( wn_ids_to_synsets . keys ( ) ) if len ( wn_ids ) != len ( nodes ) : raise ValueError ( 'Duplicate WordNet IDs in the same graph' ) # Iterate in lexicographic order over the WordNet IDs for wn_id in sorted ( wn_ids ) : synset = wn_ids_to_synsets [ wn_id ] children_ids = { child . wn_id for child in synset . children } if not children_ids . issubset ( wn_ids ) : raise ValueError ( 'Synset has children outside of the graph' ) parents_ids = { parent . wn_id for parent in synset . parents } if not parents_ids . issubset ( wn_ids ) : raise ValueError ( 'Synset has parents outside of the graph' ) node_repr = dict ( wn_id = wn_id , words = synset . words , children_ids = sorted ( children_ids ) , parents_ids = sorted ( parents_ids ) ) node_representations . append ( node_repr ) return node_representations