def _verify_arity(rule):
  """Raise ValueError if rule does not follow valid arity convention."""
  if rule.arity == 0:
    if qcfg_rule.NT_1 in rule.source:
      raise ValueError("Invalid rule: %s" % (rule,))
    if qcfg_rule.NT_2 in rule.source:
      raise ValueError("Invalid rule: %s" % (rule,))
  elif rule.arity == 1:
    if qcfg_rule.NT_1 not in rule.source:
      raise ValueError("Invalid rule: %s" % (rule,))
    if qcfg_rule.NT_2 in rule.source:
      raise ValueError("Invalid rule: %s" % (rule,))
  elif rule.arity == 2:
    if qcfg_rule.NT_1 not in rule.source:
      raise ValueError("Invalid rule: %s" % (rule,))
    if qcfg_rule.NT_2 not in rule.source:
      raise ValueError("Invalid rule: %s" % (rule,))
  return True
Raise ValueError if rule does not follow valid arity convention.
language/compgen/nqg/model/induction/derivation_utils.py