def _get_num_all_derivations(source, rules, verbose):
  """Return total number of derivations for any target."""

  def node_fn(unused_span_begin, unused_span_end, unused_rule, children):
    """Represent nodes as integer counts of possible derivations."""
    return _aggregate_counts(children)

  def postprocess_fn(nodes):
    """Merge and sum all nodes."""
    return [sum(nodes)]

  outputs = qcfg_parser.parse(
      source,
      rules,
      node_fn=node_fn,
      postprocess_cell_fn=postprocess_fn,
      verbose=verbose)

  if len(outputs) != 1:
    raise ValueError
  num_outputs = outputs[0]
  return num_outputs
Return total number of derivations for any target.
language/compgen/nqg/model/induction/codelength_utils.py