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"]
docstr: Args:
      load_path: path to folder with inverted index files
      entity_ranker: component deeppavlov.models.kbqa.rel_ranking_bert
      entities_database_filename: filename with database with entities index
      words_dict_filename: filename with words and corresponding tags
      ngrams_matrix_filename: filename with char tfidf matrix
      num_entities_for_bert_ranking: number of candidate entities for BERT ranking using description and context
      num_entities_for_conn_ranking: number of candidate entities for ranking using connections in the knowledge
          graph
      num_entities_to_return: number of candidate entities for the substring which are returned
      max_text_len: maximal length of entity context
      max_paragraph_len: maximal length of context paragraphs
      lang: russian or english
      use_description: whether to perform entity ranking by context and description
      alias_coef: coefficient which is multiplied by the substring matching confidence if the substring is the
          title of the entity
      use_tags: whether to filter candidate entities by tags
      lemmatize: whether to lemmatize tokens
      full_paragraph: whether to use full paragraph for entity context
      use_connections: whether to rank entities by connections in the knowledge graph
      kb_filename: filename with the knowledge base in HDT format
      prefixes: entity and title prefixes
      **kwargs:
docstr_tok: ["Args",":","load_path",":","path","to","folder","with","inverted","index","files","entity_ranker",":","component","deeppavlov.models.kbqa.rel_ranking_bert","entities_database_filename",":","filename","with","database","with","entities","index","words_dict_filename",":","filename","with","words","and","corresponding","tags","ngrams_matrix_filename",":","filename","with","char","tfidf","matrix","num_entities_for_bert_ranking",":","number","of","candidate","entities","for","BERT","ranking","using","description","and","context","num_entities_for_conn_ranking",":","number","of","candidate","entities","for","ranking","using","connections","in","the","knowledge","graph","num_entities_to_return",":","number","of","candidate","entities","for","the","substring","which","are","returned","max_text_len",":","maximal","length","of","entity","context","max_paragraph_len",":","maximal","length","of","context","paragraphs","lang",":","russian","or","english","use_description",":","whether","to","perform","entity","ranking","by","context","and","description","alias_coef",":","coefficient","which","is","multiplied","by","the","substring","matching","confidence","if","the","substring","is","the","title","of","the","entity","use_tags",":","whether","to","filter","candidate","entities","by","tags","lemmatize",":","whether","to","lemmatize","tokens","full_paragraph",":","whether","to","use","full","paragraph","for","entity","context","use_connections",":","whether","to","rank","entities","by","connections","in","the","knowledge","graph","kb_filename",":","filename","with","the","knowledge","base","in","HDT","format","prefixes",":","entity","and","title","prefixes","*","*","kwargs",":"]
code: def __init__(
      self,
      load_path: str,
      entity_ranker=None,
      entities_database_filename: str = None,
      words_dict_filename: str = None,
      ngrams_matrix_filename: str = None,
      num_entities_for_bert_ranking: int = 50,
      num_entities_for_conn_ranking: int = 5,
      num_entities_to_return: int = 10,
      max_text_len: int = 300,
      max_paragraph_len: int = 150,
      lang: str = "ru",
      use_descriptions: bool = True,
      alias_coef: float = 1.1,
      use_tags: bool = False,
      lemmatize: bool = False,
      full_paragraph: bool = False,
      use_connections: bool = False,
      kb_filename: str = None,
      prefixes: Dict[str, Any] = None,
      **kwargs,
  ) -> None:
      """
  
      Args:
          load_path: path to folder with inverted index files
          entity_ranker: component deeppavlov.models.kbqa.rel_ranking_bert
          entities_database_filename: filename with database with entities index
          words_dict_filename: filename with words and corresponding tags
          ngrams_matrix_filename: filename with char tfidf matrix
          num_entities_for_bert_ranking: number of candidate entities for BERT ranking using description and context
          num_entities_for_conn_ranking: number of candidate entities for ranking using connections in the knowledge
              graph
          num_entities_to_return: number of candidate entities for the substring which are returned
          max_text_len: maximal length of entity context
          max_paragraph_len: maximal length of context paragraphs
          lang: russian or english
          use_description: whether to perform entity ranking by context and description
          alias_coef: coefficient which is multiplied by the substring matching confidence if the substring is the
              title of the entity
          use_tags: whether to filter candidate entities by tags
          lemmatize: whether to lemmatize tokens
          full_paragraph: whether to use full paragraph for entity context
          use_connections: whether to rank entities by connections in the knowledge graph
          kb_filename: filename with the knowledge base in HDT format
          prefixes: entity and title prefixes
          **kwargs:
      """
      super().__init__(save_path=None, load_path=load_path)
      self.lemmatize = lemmatize
      self.num_entities_for_bert_ranking = num_entities_for_bert_ranking
      self.num_entities_for_conn_ranking = num_entities_for_conn_ranking
      self.entity_ranker = entity_ranker
      self.entities_database_filename = entities_database_filename
      self.num_entities_to_return = num_entities_to_return
      self.max_text_len = max_text_len
      self.max_paragraph_len = max_paragraph_len
      self.lang = f"@{lang}"
      if self.lang == "@en":
          self.stopwords = set(stopwords.words("english"))
          self.nlp = spacy.load("en_core_web_sm")
      elif self.lang == "@ru":
          self.stopwords = set(stopwords.words("russian"))
          self.nlp = spacy.load("ru_core_news_sm")
      self.alias_coef = alias_coef
      self.use_descriptions = use_descriptions
      self.use_connections = use_connections
      self.use_tags = use_tags
      self.full_paragraph = full_paragraph
      self.re_tokenizer = re.compile(r"[\w']+|[^\w ]")
      self.related_tags = {
          "loc": ["gpe", "country", "city", "us_state", "river"],
          "gpe": ["loc", "country", "city", "us_state"],
          "work_of_art": ["product", "law"],
          "product": ["work_of_art"],
          "law": ["work_of_art"],
          "org": ["fac", "business"],
          "business": ["org"],
      }
      self.word_searcher = None
      if words_dict_filename:
          self.word_searcher = WordSearcher(
              words_dict_filename, ngrams_matrix_filename, self.lang
          )
      self.kb_filename = kb_filename
      self.prefixes = prefixes
      self.load()
  
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 1 to create a new EntityLinker object from inherited base classes: Component, Serializable with example: obj = EntityLinker(load_path, entity_ranker, entities_database_filename, words_dict_filename, ngrams_matrix_filename, num_entities_for_bert_ranking, num_entities_for_conn_ranking, num_entities_to_return, max_text_len, max_paragraph_len, lang, use_descriptions, alias_coef, use_tags, lemmatize, full_paragraph, use_connections, kb_filename, prefixes)