dicee.query_generator

Classes

QueryGenerator

Module Contents

class dicee.query_generator.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)[source]
train_path
val_path
test_path
gen_valid
gen_test
seed
max_ans_num = 1000000.0
mode
ent2id
rel2id: Dict
ent_in: Dict
ent_out: Dict
query_name_to_struct
list2tuple(list_data)[source]
tuple2list(x: List | Tuple) List | Tuple[source]

Convert a nested tuple to a nested list.

set_global_seed(seed: int)[source]

Set seed

construct_graph(paths: List[str]) Tuple[Dict, Dict][source]

Construct graph from triples Returns dicts with incoming and outgoing edges

fill_query(query_structure: List[str | List], ent_in: Dict, ent_out: Dict, answer: int) bool[source]

Private method for fill_query logic.

achieve_answer(query: List[str | List], ent_in: Dict, ent_out: Dict) set[source]

Private method for achieve_answer logic. @TODO: Document the code

ground_queries(query_structure: List[str | List], ent_in: Dict, ent_out: Dict, small_ent_in: Dict, small_ent_out: Dict, gen_num: int, query_name: str)[source]

Generating queries and achieving answers

unmap(query_type, queries, tp_answers, fp_answers, fn_answers)[source]
unmap_query(query_structure, query, id2ent, id2rel)[source]
generate_queries(query_struct: List, gen_num: int, query_type: str)[source]

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

save_queries(query_type: str, gen_num: int, save_path: str)[source]
abstract load_queries(path)[source]
get_queries(query_type: str, gen_num: int)[source]
static save_queries_and_answers(path: str, data: List[Tuple[str, Tuple[collections.defaultdict]]]) None[source]

Save Queries into Disk

static load_queries_and_answers(path: str) List[Tuple[str, Tuple[collections.defaultdict]]][source]

Load Queries from Disk to Memory