def _maybe_get_candidate_pair(source_g, source_h, target_g, target_h):
  """Returns candidate rule pair if proposed sources and targets are valid."""
  # Check that proposed sources and targets contain same non-terminal indexes.
  nts_g = _get_non_terminals(source_g)
  if nts_g != _get_non_terminals(target_g):
    return None

  nts_h = _get_non_terminals(source_h)
  if nts_h != _get_non_terminals(target_h):
    return None

  # Canonicalize non-terminal index ordering and return candidate pair.
  source_g, target_g = _replace_tmp_nt(source_g, target_g, nts_g)
  rule_g = _make_rule(nts_g, source_g, target_g)
  rule_h = _make_rule(nts_h, source_h, target_h)
  return (rule_g, rule_h)
Returns candidate rule pair if proposed sources and targets are valid.
language/compgen/nqg/model/induction/split_utils.py