dicee.query_generator ===================== .. py:module:: dicee.query_generator Classes ------- .. autoapisummary:: dicee.query_generator.QueryGenerator Module Contents --------------- .. py:class:: QueryGenerator(train_path, val_path: str, test_path: str, ent2id: Dict = None, rel2id: Dict = None, seed: int = 1, gen_valid: bool = False, gen_test: bool = True) .. py:attribute:: train_path .. py:attribute:: val_path .. py:attribute:: test_path .. py:attribute:: gen_valid :value: False .. py:attribute:: gen_test :value: True .. py:attribute:: seed :value: 1 .. py:attribute:: max_ans_num :value: 1000000.0 .. py:attribute:: mode .. py:attribute:: ent2id :value: None .. py:attribute:: rel2id :type: Dict :value: None .. py:attribute:: ent_in :type: Dict .. py:attribute:: ent_out :type: Dict .. py:attribute:: query_name_to_struct .. py:method:: list2tuple(list_data) .. py:method:: tuple2list(x: Union[List, Tuple]) -> Union[List, Tuple] Convert a nested tuple to a nested list. .. py:method:: set_global_seed(seed: int) Set seed .. py:method:: construct_graph(paths: List[str]) -> Tuple[Dict, Dict] Construct graph from triples Returns dicts with incoming and outgoing edges .. py:method:: fill_query(query_structure: List[Union[str, List]], ent_in: Dict, ent_out: Dict, answer: int) -> bool Private method for fill_query logic. .. py:method:: achieve_answer(query: List[Union[str, List]], ent_in: Dict, ent_out: Dict) -> set Private method for achieve_answer logic. @TODO: Document the code .. py:method:: write_links(ent_out, small_ent_out) .. py:method:: ground_queries(query_structure: List[Union[str, List]], ent_in: Dict, ent_out: Dict, small_ent_in: Dict, small_ent_out: Dict, gen_num: int, query_name: str) Generating queries and achieving answers .. py:method:: unmap(query_type, queries, tp_answers, fp_answers, fn_answers) .. py:method:: unmap_query(query_structure, query, id2ent, id2rel) .. py:method:: generate_queries(query_struct: List, gen_num: int, query_type: str) Passing incoming and outgoing edges to ground queries depending on mode [train valid or text] and getting queries and answers in return @ TODO: create a class for each single query struct .. py:method:: save_queries(query_type: str, gen_num: int, save_path: str) .. py:method:: load_queries(path) :abstractmethod: .. py:method:: get_queries(query_type: str, gen_num: int) .. py:method:: save_queries_and_answers(path: str, data: List[Tuple[str, Tuple[collections.defaultdict]]]) -> None :staticmethod: Save Queries into Disk .. py:method:: load_queries_and_answers(path: str) -> List[Tuple[str, Tuple[collections.defaultdict]]] :staticmethod: Load Queries from Disk to Memory