class_docstr: Class for linking of entity substrings in the document to entities in Wikidata
class_docstr_tok: ["Class","for","linking","of","entity","substrings","in","the","document","to","entities","in","Wikidata"]
code: def merge_annotations(
      self,
      substr_batch,
      pos_batch,
      probas_batch,
      substr_batch2,
      pos_batch2,
      probas_batch2,
  ):
      log.debug(
          f"ner_chunker, substr2: {substr_batch2} --- pos2: {pos_batch2} --- probas2: {probas_batch2} --- "
          f"substr: {substr_batch} --- pos: {pos_batch} --- probas: {probas_batch}"
      )
      for i in range(len(substr_batch)):
          for key2 in substr_batch2[i]:
              substr_list2 = substr_batch2[i][key2]
              pos_list2 = pos_batch2[i][key2]
              probas_list2 = probas_batch2[i][key2]
              for substr2, pos2, probas2 in zip(
                  substr_list2, pos_list2, probas_list2
              ):
                  found = False
                  for key in substr_batch[i]:
                      pos_list = pos_batch[i][key]
                      for pos in pos_list:
                          if (
                              pos[0] <= pos2[0] <= pos[-1]
                              or pos[0] <= pos2[-1] <= pos[-1]
                          ):
                              found = True
                  if not found:
                      if key2 not in substr_batch[i]:
                          substr_batch[i][key2] = []
                          pos_batch[i][key2] = []
                          probas_batch[i][key2] = []
                      substr_batch[i][key2].append(substr2)
                      pos_batch[i][key2].append(pos2)
                      probas_batch[i][key2].append(probas2)
      for i in range(len(substr_batch)):
          for key2 in substr_batch2[i]:
              substr_list2 = substr_batch2[i][key2]
              pos_list2 = pos_batch2[i][key2]
              probas_list2 = probas_batch2[i][key2]
              for substr2, pos2, probas2 in zip(
                  substr_list2, pos_list2, probas_list2
              ):
                  for key in substr_batch[i]:
                      inds = []
                      substr_list = substr_batch[i][key]
                      pos_list = pos_batch[i][key]
                      probas_list = probas_batch[i][key]
                      for n, (substr, pos, probas) in enumerate(
                          zip(substr_list, pos_list, probas_list)
                      ):
                          if (
                              pos[0] == pos2[0] and pos[-1] < pos2[-1]
                          ) or (
                              pos[0] > pos2[0] and pos[-1] == pos2[-1]
                          ):
                              inds.append(n)
                          elif key == "EVENT" and (
                              (
                                  pos[0] >= pos2[0]
                                  and pos[-1] <= pos2[-1]
                              )
                              or (
                                  len(substr.split()) == 1
                                  and pos2[0] <= pos[0]
                              )
                          ):
                              inds.append(n)
  
                      if (
                          len(inds) > 1
                          or (
                              len(inds) == 1
                              and key in {"WORK_OF_ART", "EVENT"}
                          )
                      ) and not (key == "PERSON" and " и " in substr2):
                          inds = sorted(inds, reverse=True)
                          for ind in inds:
                              del substr_batch[i][key][ind]
                              del pos_batch[i][key][ind]
                              del probas_batch[i][key][ind]
                          substr_batch[i][key].append(substr2)
                          pos_batch[i][key].append(pos2)
                          probas_batch[i][key].append(probas2)
      return substr_batch, pos_batch, probas_batch
  
file_path: DeepPavlov/deeppavlov/models/entity_extraction/ner_chunker.py
imports: import re
  from logging import getLogger
  from string import punctuation
  from typing import List, Tuple, Union, Any
  from nltk import sent_tokenize
  from transformers import AutoTokenizer
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.models.component import Component
  from deeppavlov.core.common.chainer import Chainer
  from deeppavlov.models.entity_extraction.entity_detection_parser import EntityDetectionParser
label_desc: Use image node_id 3 for calling the NerChunkModel obj's underlying member method code with example usage: obj.merge_annotations(substr_batch, pos_batch, probas_batch, substr_batch2, pos_batch2, probas_batch2) and returns: substr_batch,  pos_batch,  probas_batch