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","."]
code: def find_top_rels(
      self,
      question: str,
      entity_ids: List[List[str]],
      triplet_info: Tuple,
  ) -> Tuple[
      List[Tuple[str, float]], Dict[str, float], Set[Tuple[str, str]]
  ]:
      ex_rels, entity_rel_conn = [], set()
      direction, source, rel_type, n_hop = triplet_info
      if source == "wiki":
          queries_list = list(
              {
                  (entity, direction, rel_type)
                  for entity_id in entity_ids
                  for entity in entity_id[: self.entities_to_leave]
              }
          )
          entity_ids_list = [elem[0] for elem in queries_list]
          parser_info_list = [
              "find_rels" for i in range(len(queries_list))
          ]
          ex_rels = self.wiki_parser(parser_info_list, queries_list)
          for ex_rels_elem, entity_id in zip(ex_rels, entity_ids_list):
              for rel in ex_rels_elem:
                  entity_rel_conn.add((entity_id, rel.split("/")[-1]))
          if self.use_wp_api_requester and ex_rels:
              ex_rels = [rel[0] for rel in ex_rels]
          ex_rels = list(set(itertools.chain.from_iterable(ex_rels)))
          if n_hop in {"1-of-2-hop", "2-hop"}:
              queries_list = list(
                  {
                      (entity, "backw", rel_type)
                      for entity_id in entity_ids
                      for entity in entity_id[: self.entities_to_leave]
                  }
              )
              entity_ids_list = [elem[0] for elem in queries_list]
              parser_info_list = [
                  "find_rels" for i in range(len(queries_list))
              ]
              ex_rels_backw = self.wiki_parser(
                  parser_info_list, queries_list
              )
              for ex_rels_elem, entity_id in zip(
                  ex_rels_backw, entity_ids_list
              ):
                  for rel in ex_rels_elem:
                      entity_rel_conn.add(
                          (entity_id, rel.split("/")[-1])
                      )
              ex_rels_backw = list(
                  set(itertools.chain.from_iterable(ex_rels_backw))
              )
              ex_rels += ex_rels_backw
          if self.delete_rel_prefix:
              ex_rels = [rel.split("/")[-1] for rel in ex_rels]
      elif source in {"rank_list_1", "rel_list_1"}:
          ex_rels = self.rels_in_ranking_queries.get(
              "one_rel_in_query", []
          )
      elif source in {"rank_list_2", "rel_list_2"}:
          ex_rels = self.rels_in_ranking_queries.get(
              "two_rels_in_query", []
          )
  
      ex_rels = [
          rel
          for rel in ex_rels
          if not any(
              [
                  rel.endswith(t_rel)
                  for t_rel in self.kb_prefixes["type_rels"]
              ]
          )
      ]
      rels_with_scores = self.rel_ranker.rank_rels(question, ex_rels)
      if (
          n_hop == "2-hop"
          and rels_with_scores
          and entity_ids
          and entity_ids[0]
      ):
          rels_1hop = [rel for rel, score in rels_with_scores]
          queries_list = [(entity_ids[0], rels_1hop[:5])]
          parser_info_list = ["find_rels_2hop"]
          ex_rels_2hop = self.wiki_parser(
              parser_info_list, queries_list
          )
          if self.delete_rel_prefix:
              ex_rels_2hop = [
                  rel.split("/")[-1] for rel in ex_rels_2hop
              ]
          rels_with_scores = self.rel_ranker.rank_rels(
              question, ex_rels_2hop
          )
  
      rels_with_scores = list(set(rels_with_scores))
      rels_with_scores = sorted(
          rels_with_scores, key=lambda x: x[1], reverse=True
      )
      rels_scores_dict = {rel: score for rel, score in rels_with_scores}
  
      return (
          rels_with_scores[: self.rels_to_leave],
          rels_scores_dict,
          entity_rel_conn,
      )
  
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 7 for calling the QueryGeneratorBase obj's underlying member method code with example usage: obj.find_top_rels(question, entity_ids, triplet_info) and returns: rels_with_scores,  rels_scores_dict,  entity_rel_conn