tools/media_engagement_preload/make_dafsa.py
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]
Generates a new DAFSA where internal nodes are merged if there is a one to
  one connection.
  
Generates a new DAFSA where internal nodes are merged if there is a one to
one connection.
Generates a new DAFSA where internal nodes are merged if there is a one to one connection .
def join_labels(dafsa):
  parentcount = { id(None): 2 }
  nodemap = { id(None): None }
  def count_parents(node):
    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):
    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]
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 ]
Generates a new DAFSA where internal nodes are merged if there is a one to
one connection.
Generates a new DAFSA where internal nodes are merged if there is a one to one connection .
"""Generates a new DAFSA where internal nodes are merged if there is a one to
  one connection.
  """ """Count incoming references""" """Create new nodes"""
dafsa