class_docstr: Class for query generation using Wikidata hdt file
class_docstr_tok: ["Class","for","query","generation","using","Wikidata","hdt","file"]
code: def check_valid_query(self, entities_rel_conn, query_hdt_seq):
      entity_rel_valid = True
      if entities_rel_conn:
          for query_hdt_elem in query_hdt_seq:
              entity, rel = "", ""
              if len(query_hdt_elem) == 3 and any(
                  [query_hdt_elem[i].startswith("?") for i in [0, 2]]
              ):
                  if "statement" in self.kb_prefixes and query_hdt_elem[
                      1
                  ].startswith(self.kb_prefixes["statement"]):
                      continue
                  else:
                      if not query_hdt_elem[0].startswith("?"):
                          entity = query_hdt_elem[0].split("/")[-1]
                      elif not query_hdt_elem[2].startswith("?"):
                          entity = query_hdt_elem[2].split("/")[-1]
                      if not query_hdt_elem[1].startswith("?"):
                          rel = query_hdt_elem[1].split("/")[-1]
                      if (
                          entity
                          and rel
                          and rel not in self.kb_prefixes["type_rels"]
                          and (entity, rel) not in entities_rel_conn
                      ):
                          entity_rel_valid = False
      return entity_rel_valid
  
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 4 for calling the QueryGenerator obj's underlying member method code with example usage: obj.check_valid_query(entities_rel_conn, query_hdt_seq) and returns: entity_rel_valid