class_docstr: Class for query generation using Wikidata hdt file
class_docstr_tok: ["Class","for","query","generation","using","Wikidata","hdt","file"]
code: def query_parser(
      self,
      question: str,
      queries_info: Dict[str, str],
      entity_ids: List[List[str]],
      type_ids: List[List[str]],
      answer_types: Set[str],
      rels_from_template: Optional[List[Tuple[str]]] = None,
  ) -> Union[List[Dict[str, Any]], list]:
      parsed_queries_info, rels_scores_dict = self.parse_queries_info(
          question,
          queries_info,
          entity_ids,
          type_ids,
          rels_from_template,
      )
      queries_list, parser_info_list, entity_conf_list = [], [], []
      new_combs_list, query_info_list = [], []
      combs_num_list = [
          len(parsed_query_info["all_combs_list"])
          for parsed_query_info in parsed_queries_info
      ]
      if combs_num_list:
          max_comb_nums = max(combs_num_list)
      else:
          max_comb_nums = 0
      for comb_num in range(max_comb_nums):
          for parsed_query_info in parsed_queries_info:
              if comb_num < min(
                  len(parsed_query_info["all_combs_list"]),
                  self.max_comb_num,
              ):
                  query_triplets = parsed_query_info["query_triplets"]
                  query_sequence = parsed_query_info["query_sequence"]
                  rels_from_query = parsed_query_info["rels_from_query"]
                  answer_ent = parsed_query_info["answer_ent"]
                  filter_info = parsed_query_info["filter_info"]
                  order_info = parsed_query_info["order_info"]
                  rel_types = parsed_query_info["rel_types"]
                  unk_rels = parsed_query_info["unk_rels"]
                  return_if_found = parsed_query_info["return_if_found"]
                  entities_rel_conn = parsed_query_info[
                      "entities_rel_conn"
                  ]
                  combs = parsed_query_info["all_combs_list"][comb_num]
                  if combs[0][-1] == 0:
                      entity_conf_list.append(1.0)
                  else:
                      entity_conf_list.append(0.9)
                  query_hdt_seq = [
                      fill_query(
                          query_hdt_elem,
                          combs[0],
                          combs[1],
                          combs[2],
                          self.map_query_str_to_kb,
                      )
                      for query_hdt_elem in query_sequence
                  ]
                  if comb_num == 0:
                      log.debug(
                          f"\n______________________\nfilled query: {query_hdt_seq}\n______________________\n"
                      )
  
                  entity_rel_valid = self.check_valid_query(
                      entities_rel_conn, query_hdt_seq
                  )
                  if entity_rel_valid:
                      new_combs_list.append(combs)
                      queries_list.append(
                          (
                              answer_ent,
                              rels_from_query,
                              query_hdt_seq,
                              filter_info,
                              order_info,
                              answer_types,
                              rel_types,
                              return_if_found,
                          )
                      )
                      query_info_list.append(
                          (
                              query_triplets,
                              query_hdt_seq,
                              answer_ent,
                              filter_info,
                              order_info,
                          )
                      )
                      parser_info_list.append("query_execute")
                  if comb_num < 3 and unk_rels:
                      unk_query_sequence = copy.deepcopy(query_sequence)
                      unk_rels_from_query = copy.deepcopy(
                          rels_from_query
                      )
                      for unk_rel, rel_var in zip(
                          unk_rels, ["?p", "?p2"]
                      ):
                          unk_query_sequence[int(unk_rel) - 1][
                              1
                          ] = rel_var
                          combs[-1][int(unk_rel) - 1] = (rel_var, 1.0)
                          if rel_var not in rels_from_query:
                              unk_rels_from_query.append(rel_var)
                      query_hdt_seq = [
                          fill_query(
                              query_hdt_elem,
                              combs[0],
                              combs[1],
                              combs[2],
                              self.map_query_str_to_kb,
                          )
                          for query_hdt_elem in unk_query_sequence
                      ]
                      new_combs_list.append(combs)
                      queries_list.append(
                          (
                              answer_ent,
                              unk_rels_from_query,
                              query_hdt_seq,
                              filter_info,
                              order_info,
                              answer_types,
                              rel_types,
                              return_if_found,
                          )
                      )
                      query_info_list.append(
                          (
                              query_triplets,
                              query_hdt_seq,
                              answer_ent,
                              filter_info,
                              order_info,
                          )
                      )
                      parser_info_list.append("query_execute")
  
      outputs_list = self.wiki_parser(parser_info_list, queries_list)
      outputs = self.parse_outputs(
          outputs_list,
          new_combs_list,
          query_info_list,
          entity_conf_list,
          rels_scores_dict,
      )
      return outputs
  
imports: import copy
  import itertools
  import re
  from collections import defaultdict
  from logging import getLogger
  from typing import Tuple, List, Optional, Union, Dict, Any, Set
  import nltk
  import numpy
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.models.component import Component
  from deeppavlov.models.kbqa.query_generator_base import QueryGeneratorBase
  from deeppavlov.models.kbqa.rel_ranking_infer import RelRankerInfer
  from deeppavlov.models.kbqa.utils import extract_year, extract_number, make_combs, fill_query, find_query_features, make_sparql_query, merge_sparql_query
  from deeppavlov.models.kbqa.wiki_parser import WikiParser
label_desc: Use image node_id 5 for calling the QueryGenerator obj's underlying member method code with example usage: obj.query_parser(question, queries_info, entity_ids, type_ids, answer_types, rels_from_template) and returns: outputs