def _get_free_nt_replacement(nts):
  """Get the next free NT index."""
  # For example
  # nts = {NT_1, NT_3} will return NT_2.
  # nts = {NT_1, NT_2} will return NT_3.
  nt_indices = set(qcfg_rule.get_nt_index(nt) for nt in nts)
  # The new NT indices are {NT_1, ..., NT_{n+1}}
  missing_idx = set(range(1, len(nts) + 2)) - nt_indices
  return str(qcfg_rule.NT(missing_idx.pop()))
Get the next free NT index.
language/compgen/csl/induction/unification_utils.py