def get_rhs_emb_idx_map(rules):
  """Return map from (rule, nt_idx) to integer rhs_emb_idx."""
  # Key is (rule, nt_idx).
  rhs_emb_idx_map = {}
  # Add special entry for "root rule".
  rhs_emb_idx_map[(parsing_utils.ROOT_RULE_KEY, 0)] = 0
  # Add entries for other rules.
  max_num_nts = 0
  idx = 1
  for rule in sorted(rules):
    num_nts = qcfg_rule.get_num_nts(rule.source)
    max_num_nts = max(max_num_nts, num_nts)
    for nt_idx in range(num_nts):
      rhs_emb_idx_map[(rule, nt_idx)] = idx
      idx += 1
  print("max_num_nts: %s" % max_num_nts)
  print("len(rhs_emb_idx_map): %s" % len(rhs_emb_idx_map))
  return rhs_emb_idx_map
Return map from (rule, nt_idx) to integer rhs_emb_idx.
language/compgen/csl/model/data/example_converter.py