def _replace_nonterminal(node_1_string, node_1_idx, node_2_string):
  """Replace corresponding non-terminal in node_2_string with node_1_string."""
  non_terminals = 0
  new_tokens = []
  for token in node_2_string.split():
    if token == _PLACEHOLDER:
      if non_terminals == node_1_idx:
        new_tokens.append(node_1_string)
      else:
        new_tokens.append(token)
      non_terminals += 1
    else:
      new_tokens.append(token)
  return " ".join(new_tokens)
Replace corresponding non-terminal in node_2_string with node_1_string.
language/compgen/nqg/tasks/spider/tmcd_utils.py