def rule_from_string(rule_str):
  """Parse rule in format 'source SEPARATOR target'."""
  splits = rule_str.split(SEPARATOR)
  if len(splits) != 2:
    raise ValueError("Invalid rule string: %s" % rule_str)
  source_str, target_str = splits
  source = source_str.strip().split()
  target = target_str.strip().split()
  arity = _get_arity(source)
  return QCFGRule(tuple(source), tuple(target), arity)
Parse rule in format 'source SEPARATOR target'.
language/compgen/nqg/model/qcfg/qcfg_rule.py