def get_target_node(source, target, rules):
  """Return node corresponding to parses for target, or None."""
  tokens = source.split(" ")

  def node_fn(span_begin, span_end, rule, children):
    target_string = qcfg_rule.apply_target(
        rule, [node.target_string for node in children])
    return RuleApplicationNode(rule, children, span_begin, span_end,
                               target_string)

  def postprocess_fn(nodes):
    nodes = filter_nodes(nodes, target)
    return _aggregate(nodes)

  nodes = qcfg_parser.parse(
      tokens, rules, node_fn=node_fn, postprocess_cell_fn=postprocess_fn)

  # Filter for nodes where target_string matches target exactly.
  ret_nodes = []
  for node in nodes:
    if node.target_string == target:
      ret_nodes.append(node)

  if not ret_nodes:
    return None

  if len(ret_nodes) > 1:
    raise ValueError

  return ret_nodes[0]
Return node corresponding to parses for target, or None.
language/compgen/nqg/model/parser/data/parsing_utils.py