parameters: (dafsa)
return_statement: return [join(node) for node in dafsa]
docstring: Generates a new DAFSA where internal nodes are merged if there is a one to
    one connection.
docstring_summary: Generates a new DAFSA where internal nodes are merged if there is a one to
    one connection.
docstring_tokens: Generates a new DAFSA where internal nodes are merged if there is a one to one connection .
function: def join_labels(dafsa):
    """Generates a new DAFSA where internal nodes are merged if there is a one to
    one connection.
    """
    parentcount = { id(None): 2 }
    nodemap = { id(None): None }
  
    def count_parents(node):
      """Count incoming references"""
      if id(node) in parentcount:
        parentcount[id(node)] += 1
      else:
        parentcount[id(node)] = 1
        for child in node[1]:
          count_parents(child)
  
    def join(node):
      """Create new nodes"""
      if id(node) not in nodemap:
        children = [join(child) for child in node[1]]
        if len(children) == 1 and parentcount[id(node[1][0])] == 1:
          child = children[0]
          nodemap[id(node)] = (node[0] + child[0], child[1])
        else:
          nodemap[id(node)] = (node[0], children)
      return nodemap[id(node)]
  
    for node in dafsa:
      count_parents(node)
    return [join(node) for node in dafsa]
function_tokens: def join_labels ( dafsa ) : parentcount = { id ( None ) : 2 } nodemap = { id ( None ) : None } def count_parents ( node ) : """Count incoming references""" if id ( node ) in parentcount : parentcount [ id ( node ) ] += 1 else : parentcount [ id ( node ) ] = 1 for child in node [ 1 ] : count_parents ( child ) def join ( node ) : """Create new nodes""" if id ( node ) not in nodemap : children = [ join ( child ) for child in node [ 1 ] ] if len ( children ) == 1 and parentcount [ id ( node [ 1 ] [ 0 ] ) ] == 1 : child = children [ 0 ] nodemap [ id ( node ) ] = ( node [ 0 ] + child [ 0 ] , child [ 1 ] ) else : nodemap [ id ( node ) ] = ( node [ 0 ] , children ) return nodemap [ id ( node ) ] for node in dafsa : count_parents ( node ) return [ join ( node ) for node in dafsa ]