class_docstr: This class takes as input entity substrings, defines the template of the query and
  fills the slots of the template with candidate entities and relations.
class_docstr_tok: ["This","class","takes","as","input","entity","substrings",",","defines","the","template","of","the","query","and","fills","the","slots","of","the","template","with","candidate","entities","and","relations","."]
docstr: Args:
      template_matcher: component deeppavlov.models.kbqa.template_matcher
      rel_ranker: component deeppavlov.models.kbqa.rel_ranking_infer
      load_path: path to folder with wikidata files
      sparql_queries_filename: file with sparql query templates
      entity_linker: component deeppavlov.models.entity_extraction.entity_linking for linking of entities
      rels_in_ranking_queries_fname: file with list of rels in queries for questions with ranking
      wiki_parser: component deeppavlov.models.kbqa.wiki_parser
      entities_to_leave: how many entities to leave after entity linking
      rels_to_leave: how many relations to leave after relation ranking
      syntax_structure_known: if syntax tree parser was used to define query template type
      use_wp_api_requester: whether deeppavlov.models.api_requester.api_requester component will be used for
          Wiki Parser
      use_el_api_requester: whether deeppavlov.models.api_requester.api_requester component will be used for
          Entity Linking
      use_alt_templates: whether to use alternative templates if no answer was found for default query template
      delete_rel_prefix: whether to delete prefix in relations
      kb_prefixes: prefixes for entities, relations and types in the knowledge base
docstr_tok: ["Args",":","template_matcher",":","component","deeppavlov.models.kbqa.template_matcher","rel_ranker",":","component","deeppavlov.models.kbqa.rel_ranking_infer","load_path",":","path","to","folder","with","wikidata","files","sparql_queries_filename",":","file","with","sparql","query","templates","entity_linker",":","component","deeppavlov.models.entity_extraction.entity_linking","for","linking","of","entities","rels_in_ranking_queries_fname",":","file","with","list","of","rels","in","queries","for","questions","with","ranking","wiki_parser",":","component","deeppavlov.models.kbqa.wiki_parser","entities_to_leave",":","how","many","entities","to","leave","after","entity","linking","rels_to_leave",":","how","many","relations","to","leave","after","relation","ranking","syntax_structure_known",":","if","syntax","tree","parser","was","used","to","define","query","template","type","use_wp_api_requester",":","whether","deeppavlov.models.api_requester.api_requester","component","will","be","used","for","Wiki","Parser","use_el_api_requester",":","whether","deeppavlov.models.api_requester.api_requester","component","will","be","used","for","Entity","Linking","use_alt_templates",":","whether","to","use","alternative","templates","if","no","answer","was","found","for","default","query","template","delete_rel_prefix",":","whether","to","delete","prefix","in","relations","kb_prefixes",":","prefixes","for","entities",",","relations","and","types","in","the","knowledge","base"]
code: def __init__(
      self,
      template_matcher: TemplateMatcher,
      rel_ranker: RelRankerInfer,
      load_path: str,
      sparql_queries_filename: str,
      entity_linker: EntityLinker,
      rels_in_ranking_queries_fname: str = None,
      wiki_parser=None,
      entities_to_leave: int = 5,
      rels_to_leave: int = 7,
      syntax_structure_known: bool = False,
      use_wp_api_requester: bool = False,
      use_el_api_requester: bool = False,
      use_alt_templates: bool = True,
      delete_rel_prefix: bool = True,
      kb_prefixes: Dict[str, str] = None,
      *args,
      **kwargs,
  ) -> None:
      """
  
      Args:
          template_matcher: component deeppavlov.models.kbqa.template_matcher
          rel_ranker: component deeppavlov.models.kbqa.rel_ranking_infer
          load_path: path to folder with wikidata files
          sparql_queries_filename: file with sparql query templates
          entity_linker: component deeppavlov.models.entity_extraction.entity_linking for linking of entities
          rels_in_ranking_queries_fname: file with list of rels in queries for questions with ranking
          wiki_parser: component deeppavlov.models.kbqa.wiki_parser
          entities_to_leave: how many entities to leave after entity linking
          rels_to_leave: how many relations to leave after relation ranking
          syntax_structure_known: if syntax tree parser was used to define query template type
          use_wp_api_requester: whether deeppavlov.models.api_requester.api_requester component will be used for
              Wiki Parser
          use_el_api_requester: whether deeppavlov.models.api_requester.api_requester component will be used for
              Entity Linking
          use_alt_templates: whether to use alternative templates if no answer was found for default query template
          delete_rel_prefix: whether to delete prefix in relations
          kb_prefixes: prefixes for entities, relations and types in the knowledge base
      """
      super().__init__(save_path=None, load_path=load_path)
      self.template_matcher = template_matcher
      self.entity_linker = entity_linker
      self.wiki_parser = wiki_parser
      self.rel_ranker = rel_ranker
      self.rels_in_ranking_queries_fname = rels_in_ranking_queries_fname
      self.rels_in_ranking_queries = {}
      self.entities_to_leave = entities_to_leave
      self.rels_to_leave = rels_to_leave
      self.syntax_structure_known = syntax_structure_known
      self.use_wp_api_requester = use_wp_api_requester
      self.use_el_api_requester = use_el_api_requester
      self.use_alt_templates = use_alt_templates
      self.sparql_queries_filename = sparql_queries_filename
      self.delete_rel_prefix = delete_rel_prefix
      self.kb_prefixes = kb_prefixes
  
      self.load()
  
imports: import itertools
  import json
  from logging import getLogger
  from typing import Tuple, List, Dict, Optional, Union, Any, Set
  from bs4 import BeautifulSoup
  from whapi import search, get_html
  from deeppavlov.core.commands.utils import expand_path
  from deeppavlov.core.common.file import read_json
  from deeppavlov.core.models.component import Component
  from deeppavlov.core.models.serializable import Serializable
  from deeppavlov.models.entity_extraction.entity_linking import EntityLinker
  from deeppavlov.models.kbqa.rel_ranking_infer import RelRankerInfer
  from deeppavlov.models.kbqa.template_matcher import TemplateMatcher
  from deeppavlov.models.kbqa.utils import preprocess_template_queries
label_desc: Use image node_id 1 to create a new QueryGeneratorBase object from inherited base classes: Component, Serializable with example: obj = QueryGeneratorBase(template_matcher, rel_ranker, load_path, sparql_queries_filename, entity_linker, rels_in_ranking_queries_fname, wiki_parser, entities_to_leave, rels_to_leave, syntax_structure_known, use_wp_api_requester, use_el_api_requester, use_alt_templates, delete_rel_prefix, kb_prefixes)