class_docstr: Class for query generation using Wikidata hdt file
class_docstr_tok: ["Class","for","query","generation","using","Wikidata","hdt","file"]
code: def parse_queries_info(
      self,
      question,
      queries_info,
      entity_ids,
      type_ids,
      rels_from_template,
  ):
      parsed_queries_info = []
      question_tokens = nltk.word_tokenize(question)
      rels_scores_dict = {}
      for query_info in queries_info:
          query = query_info["query_template"].lower()
          for old_tok, new_tok in self.replace_tokens:
              query = query.replace(old_tok, new_tok)
          log.debug(
              f"\n_______________________________\nquery: {query}\n_______________________________\n"
          )
          entities_and_types_select = query_info[
              "entities_and_types_select"
          ]
          rels_for_search = query_info["rank_rels"]
          rel_types = query_info["rel_types"]
          n_hops = query_info["n_hops"]
          unk_rels = query_info.get("unk_rels", [])
          query_seq_num = query_info["query_sequence"]
          return_if_found = query_info["return_if_found"]
          log.debug(
              f"(query_parser)query: {query}, rels_for_search {rels_for_search}, rel_types {rel_types} "
              f"n_hops {n_hops}, {query_seq_num}, {return_if_found}"
          )
          query_triplets = re.findall("{[ ]?(.*?)[ ]?}", query)[
              0
          ].split(" . ")
          log.debug(f"(query_parser)query_triplets: {query_triplets}")
          query_triplets_split = [
              triplet.split(" ")[:3] for triplet in query_triplets
          ]
          property_types = {}
          for rel_type, query_triplet in zip(
              rel_types, query_triplets_split
          ):
              if (
                  query_triplet[1].startswith("?")
                  and rel_type == "qualifier"
              ):
                  property_types[query_triplet[1]] = rel_type
          query_sequence_dict = {
              num + 1: triplet
              for num, triplet in enumerate(query_triplets_split)
          }
          query_sequence = []
          for i in query_seq_num:
              query_sequence.append(query_sequence_dict[i])
          triplet_info_list = [
              (
                  "forw" if triplet[2].startswith("?") else "backw",
                  search_source,
                  rel_type,
                  n_hop,
              )
              for search_source, triplet, rel_type, n_hop in zip(
                  rels_for_search, query_sequence, rel_types, n_hops
              )
              if search_source != "do_not_rank"
          ]
          log.debug(
              f"(query_parser)query_sequence_dict: {query_sequence_dict} --- rel_directions: "
              f"{triplet_info_list} --- query_sequence: {query_sequence}"
          )
          entity_ids = [
              entity[: self.entities_to_leave] for entity in entity_ids
          ]
          rels, entities_rel_conn = [], set()
          if rels_from_template is not None:
              rels = [
                  [(rel, 1.0) for rel in rel_list]
                  for rel_list in rels_from_template
              ]
          elif not rels:
              for triplet_info in triplet_info_list:
                  (
                      ex_rels,
                      cur_rels_scores_dict,
                      entity_rel_conn,
                  ) = self.find_top_rels(
                      question, entity_ids, triplet_info
                  )
                  rels.append(ex_rels)
                  rels_scores_dict = {
                      **rels_scores_dict,
                      **cur_rels_scores_dict,
                  }
                  entities_rel_conn = entities_rel_conn.union(
                      entity_rel_conn
                  )
          log.debug(f"(query_parser)rels: {rels}")
          rels_from_query = [
              triplet[1]
              for triplet in query_triplets_split
              if triplet[1].startswith("?")
          ]
          qualifier_rels = [
              triplet[1]
              for triplet in query_triplets_split
              if triplet[1].startswith("pq:P")
          ]
  
          (
              answer_ent,
              order_info,
              filter_from_query,
          ) = find_query_features(query, qualifier_rels, question)
          log.debug(
              f"(query_parser) filter_from_query: {filter_from_query} --- order_info: {order_info}"
          )
  
          year = extract_year(question_tokens, question)
          number = extract_number(question_tokens, question)
          log.debug(f"year {year}, number {number}")
          if year:
              filter_info = [
                  (elem[0], elem[1].replace("n", year))
                  for elem in filter_from_query
              ]
          elif number:
              filter_info = [
                  (elem[0], elem[1].replace("n", number))
                  for elem in filter_from_query
              ]
          else:
              filter_info = [
                  elem for elem in filter_from_query if elem[1] != "n"
              ]
          for unk_prop, prop_type in property_types.items():
              filter_info.append((unk_prop, prop_type))
          log.debug(
              f"(query_parser)filter_from_query: {filter_from_query}"
          )
          rel_combs = make_combs(rels, permut=False)
  
          entity_positions, type_positions = [
              elem.split("_")
              for elem in entities_and_types_select.split(" ")
          ]
          log.debug(
              f"entity_positions {entity_positions}, type_positions {type_positions}"
          )
          selected_entity_ids, selected_type_ids = [], []
          if len(entity_ids) > 1 and len(entity_positions) == 1:
              selected_entity_ids = []
              for j in range(max([len(elem) for elem in entity_ids])):
                  for elem in entity_ids:
                      if j < len(elem):
                          selected_entity_ids.append(elem[j])
              selected_entity_ids = [selected_entity_ids]
          elif entity_ids:
              selected_entity_ids = [
                  entity_ids[int(pos) - 1]
                  for pos in entity_positions
                  if int(pos) > 0
              ]
          if type_ids:
              selected_type_ids = [
                  type_ids[int(pos) - 1][: self.types_to_leave]
                  for pos in type_positions
                  if int(pos) > 0
              ]
          entity_combs = make_combs(selected_entity_ids, permut=True)
          type_combs = make_combs(selected_type_ids, permut=False)
          log.debug(
              f"(query_parser)entity_combs: {entity_combs[:3]}, type_combs: {type_combs[:3]},"
              f" rel_combs: {rel_combs[:3]}"
          )
  
          all_combs_list = list(
              itertools.product(entity_combs, type_combs, rel_combs)
          )
          all_combs_list = sorted(
              all_combs_list,
              key=lambda x: (sum([elem[-1] for elem in x]), x[0][-1]),
          )
          parsed_queries_info.append(
              {
                  "query_triplets": query_triplets,
                  "query_sequence": query_sequence,
                  "rels_from_query": rels_from_query,
                  "answer_ent": answer_ent,
                  "filter_info": filter_info,
                  "order_info": order_info,
                  "rel_types": rel_types,
                  "unk_rels": unk_rels,
                  "return_if_found": return_if_found,
                  "selected_entity_ids": selected_entity_ids,
                  "selected_type_ids": selected_type_ids,
                  "rels": rels,
                  "entities_rel_conn": entities_rel_conn,
                  "entity_combs": entity_combs,
                  "type_combs": type_combs,
                  "rel_combs": rel_combs,
                  "all_combs_list": all_combs_list,
              }
          )
      return parsed_queries_info, rels_scores_dict
  
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 3 for calling the QueryGenerator obj's underlying member method code with example usage: obj.parse_queries_info(question, queries_info, entity_ids, type_ids, rels_from_template) and returns: parsed_queries_info,  rels_scores_dict