def apply_target(rule, substitutions):
  """Return target string with non-terminals replaced with substitutions."""
  if rule.arity != len(substitutions):
    raise ValueError
  output = []
  for token in rule.target:
    if token == NT_1:
      output.append(substitutions[0])
    elif token == NT_2:
      output.append(substitutions[1])
    else:
      output.append(token)
  return " ".join(output)
Return target string with non-terminals replaced with substitutions.
language/compgen/nqg/model/qcfg/qcfg_rule.py