def canonicalize_nts(source, target, arity):
  """Follows convention of source indexes being in order."""
  if arity == 1:
    if qcfg_rule.NT_2 in source:
      source = rhs_replace(source, [qcfg_rule.NT_2], qcfg_rule.NT_1)
      target = rhs_replace(target, [qcfg_rule.NT_2], qcfg_rule.NT_1)
  elif arity == 2:
    if qcfg_rule.NT_1 not in source or qcfg_rule.NT_2 not in source:
      raise ValueError("Bad arity 2 source: %s" % (source,))
    if source.index(qcfg_rule.NT_1) > source.index(qcfg_rule.NT_2):
      source = _swap_nt_order(source)
      target = _swap_nt_order(target)
  return source, target
Follows convention of source indexes being in order.
language/compgen/nqg/model/induction/rule_utils.py