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 __call__(
      self,
      substr_batch: List[List[str]],
      tags_batch: List[List[str]] = None,
      probas_batch: List[List[float]] = None,
      sentences_batch: List[List[str]] = None,
      offsets_batch: List[List[List[int]]] = None,
      sentences_offsets_batch: List[List[Tuple[int, int]]] = None,
      entities_to_link_batch: List[List[int]] = None,
  ):
      if (
          not sentences_offsets_batch
          or sentences_offsets_batch[0] is None
      ) and sentences_batch is not None:
          sentences_offsets_batch = []
          for sentences_list in sentences_batch:
              sentences_offsets_list = []
              start = 0
              for sentence in sentences_list:
                  end = start + len(sentence)
                  sentences_offsets_list.append([start, end])
                  start = end + 1
              sentences_offsets_batch.append(sentences_offsets_list)
  
      if sentences_batch is None:
          sentences_batch = [[] for _ in substr_batch]
          sentences_offsets_batch = [[] for _ in substr_batch]
  
      if (
          not entities_to_link_batch
          or entities_to_link_batch[0] is None
      ):
          entities_to_link_batch = [
              [1 for _ in substr_list] for substr_list in substr_batch
          ]
  
      log.debug(
          f"substr: {substr_batch} --- sentences_batch: {sentences_batch} --- offsets: {offsets_batch}"
      )
      if (
          not offsets_batch or offsets_batch[0] is None
      ) and sentences_batch:
          offsets_batch = []
          for substr_list, sentences_list in zip(
              substr_batch, sentences_batch
          ):
              text = " ".join(sentences_list).lower()
              log.debug(f"text {text}")
              offsets_list = []
              for substr in substr_list:
                  st_offset = text.find(substr.lower())
                  end_offset = st_offset + len(substr)
                  offsets_list.append([st_offset, end_offset])
              offsets_batch.append(offsets_list)
      ids_batch, conf_batch, pages_batch, labels_batch = [], [], [], []
      for (
          substr_list,
          offsets_list,
          tags_list,
          probas_list,
          sentences_list,
          sentences_offsets_list,
          entities_to_link,
      ) in zip(
          substr_batch,
          offsets_batch,
          tags_batch,
          probas_batch,
          sentences_batch,
          sentences_offsets_batch,
          entities_to_link_batch,
      ):
          (
              ids_list,
              conf_list,
              pages_list,
              labels_list,
          ) = self.link_entities(
              substr_list,
              offsets_list,
              tags_list,
              probas_list,
              sentences_list,
              sentences_offsets_list,
              entities_to_link,
          )
          log.debug(f"ids_list {ids_list} conf_list {conf_list}")
          if self.num_entities_to_return == 1:
              pages_list = [pages[0] for pages in pages_list]
          else:
              pages_list = [
                  pages[: len(ids)]
                  for pages, ids in zip(pages_list, ids_list)
              ]
          ids_batch.append(ids_list)
          conf_batch.append(conf_list)
          pages_batch.append(pages_list)
          labels_batch.append(labels_list)
      return ids_batch, conf_batch, pages_batch, labels_batch
  
imports: import re
  import sqlite3
  from logging import getLogger
  from typing import List, Dict, Tuple, Any, Union
  from collections import defaultdict
  import nltk
  import spacy
  from hdt import HDTDocument
  from nltk.corpus import stopwords
  from rapidfuzz import fuzz
  from deeppavlov.core.commands.utils import expand_path
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.models.component import Component
  from deeppavlov.core.models.serializable import Serializable
  from deeppavlov.models.entity_extraction.find_word import WordSearcher
label_desc: Use image node_id 4 for calling the EntityLinker obj's underlying member method code with example usage: obj.__call__(substr_batch, tags_batch, probas_batch, sentences_batch, offsets_batch, sentences_offsets_batch, entities_to_link_batch) and returns: ids_batch,  conf_batch,  pages_batch,  labels_batch