class_docstr: 基于AC自动机实现用户干预的功能
docstr: 使用人工干预词典修正lac模型的输出
docstr_tok: ["\u4f7f\u7528\u4eba\u5de5\u5e72\u9884\u8bcd\u5178\u4fee\u6b63lac\u6a21\u578b\u7684\u8f93\u51fa"]
code: def parse_customization(self, query, lac_tags):
      """使用人工干预词典修正lac模型的输出"""
  
      def ac_postpress(ac_res):
          ac_res.sort()
          i = 1
          while i < len(ac_res):
              if (
                  ac_res[i - 1][0] < ac_res[i][0]
                  and ac_res[i][0] <= ac_res[i - 1][1]
              ):
                  ac_res.pop(i)
                  continue
              i += 1
          return ac_res
  
      if not self.ac:
          print("Customized dict is not loaded.")
          return
  
      ac_res = self.ac.search(query)
  
      ac_res = ac_postpress(ac_res)
  
      for begin, end in ac_res:
          phrase = query[begin : end + 1]
          index = begin
  
          tags, offsets = self.dictitem[phrase]
          for tag, offset in zip(tags, offsets):
              while index < begin + offset:
                  if len(tag) == 0:
                      lac_tags[index] = lac_tags[index][:-1] + "I"
                  else:
                      lac_tags[index] = tag + "-I"
                  index += 1
  
          lac_tags[begin] = lac_tags[begin][:-1] + "B"
          for offset in offsets:
              index = begin + offset
              if index < len(lac_tags):
                  lac_tags[index] = lac_tags[index][:-1] + "B"
  
imports: from io import open
  from .ahocorasick import Ahocorasick
label_desc: Use image node_id 3 for calling the Customization obj's underlying member method code with example usage: obj.parse_customization(query, lac_tags) and returns: ac_res