parameters: (seq_cts, threshold=0.9)
return_statement: return keepers[1:]
docstring: 'seq_cts' is the list of ("B[];W[];...", count) sequences to prune.
      Suppose they contain
      ("A;B;C;D;", 1000),
      ("A;B;C;D;E;", 500),
      ("A;B;C;D;E;F;", 490),
      ("A;B;C;D;X;", 500),
      ("A;B;C;D;X;Y;", 490)
      , etc.
      We would want the longest sequences (ABCDXY, ABCDEF), and their common root,
      (ABCD), and we would remove the intermediate sequences.
  
      Returns a list formatted like seq_cts
docstring_summary: 'seq_cts' is the list of ("B[];W[];...", count) sequences to prune.
      Suppose they contain
      ("A;B;C;D;", 1000),
      ("A;B;C;D;E;", 500),
      ("A;B;C;D;E;F;", 490),
      ("A;B;C;D;X;", 500),
      ("A;B;C;D;X;Y;", 490)
      , etc.
      We would want the longest sequences (ABCDXY, ABCDEF), and their common root,
      (ABCD), and we would remove the intermediate sequences.
docstring_tokens: seq_cts is the list of ( B [] ; W [] ; ... count ) sequences to prune . Suppose they contain ( A ; B ; C ; D ; 1000 ) ( A ; B ; C ; D ; E ; 500 ) ( A ; B ; C ; D ; E ; F ; 490 ) ( A ; B ; C ; D ; X ; 500 ) ( A ; B ; C ; D ; X ; Y ; 490 ) etc . We would want the longest sequences ( ABCDXY ABCDEF ) and their common root ( ABCD ) and we would remove the intermediate sequences .
function: def collapse_common_prefix(seq_cts, threshold=0.9):
      """
      'seq_cts' is the list of ("B[];W[];...", count) sequences to prune.
      Suppose they contain
      ("A;B;C;D;", 1000),
      ("A;B;C;D;E;", 500),
      ("A;B;C;D;E;F;", 490),
      ("A;B;C;D;X;", 500),
      ("A;B;C;D;X;Y;", 490)
      , etc.
      We would want the longest sequences (ABCDXY, ABCDEF), and their common root,
      (ABCD), and we would remove the intermediate sequences.
  
      Returns a list formatted like seq_cts
      """
  
      # Build the Trie.
      root = MoveTrieNode("", 0)
      for seq, ct in seq_cts:
          root.add(seq, ct)
  
      node = root
      keepers = []
      to_visit = []
  
      # We want to keep a node if:
      # a. it has no parent OR no kids
      # b. it has no child with > threshold frac of our own kids.
      while True:
          to_visit.extend(list(node.children))
  
          if not node.parent or not node.children:
              keepers.append((node.sequence_to(), node.count))
          else:
              all_one_kid = False
              for k in node.children:
                  if k.count > (node.count * threshold):
                      all_one_kid = True
                      break # We're not checking that freq(parent) >= sum(freq(kids))
              if not all_one_kid:
                  keepers.append((node.sequence_to(), node.count))
          if to_visit:
              node = to_visit.pop(0)
          else:
              break
  
      #truncate the first [empty] node.
      return keepers[1:]
function_tokens: def collapse_common_prefix ( seq_cts , threshold = 0.9 ) : # Build the Trie. root = MoveTrieNode ( "" , 0 ) for seq , ct in seq_cts : root . add ( seq , ct ) node = root keepers = [ ] to_visit = [ ] # We want to keep a node if: # a. it has no parent OR no kids # b. it has no child with > threshold frac of our own kids. while True : to_visit . extend ( list ( node . children ) ) if not node . parent or not node . children : keepers . append ( ( node . sequence_to ( ) , node . count ) ) else : all_one_kid = False for k in node . children : if k . count > ( node . count * threshold ) : all_one_kid = True break # We're not checking that freq(parent) >= sum(freq(kids)) if not all_one_kid : keepers . append ( ( node . sequence_to ( ) , node . count ) ) if to_visit : node = to_visit . pop ( 0 ) else : break #truncate the first [empty] node. return keepers [ 1 : ]