code: def __init__(self, rules):
      import datrie
  
      def prefixes(rule):
          return (str(o.constant_prefix()) for o in rule.products())
  
      def reverse_suffixes(rule):
          return (
              str(o.constant_suffix())[::-1] for o in rule.products()
          )
  
      def calc_trie(subpatterns):
          t = datrie.Trie(
              "".join(p for rule in rules for p in subpatterns(rule))
          )
          empty = list()
          for rule in rules:
              has_empty = False
              for p in subpatterns(rule):
                  if not p:
                      has_empty = True
                  if p not in t:
                      t[p] = [rule]
                  else:
                      t[p].append(rule)
              if has_empty:
                  empty.append(rule)
          return t, empty
  
      self.prefix_trie, self.empty_prefix = calc_trie(prefixes)
      self.suffix_trie, self.empty_suffix = calc_trie(reverse_suffixes)
  
label_desc: Use image node_id 1 to create a new OutputIndex object  with example: obj = OutputIndex(rules)