From bb0049ee9d96183182457f0cb0cf2de3090d7c02 Mon Sep 17 00:00:00 2001 From: Pangjing-Wu Date: Wed, 22 May 2024 13:37:20 +0000 Subject: [PATCH] fix bugs in freebase --- ToG/freebase_func.py | 4 ++-- ToG/main_freebase.py | 2 +- ToG/utils.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ToG/freebase_func.py b/ToG/freebase_func.py index 09d8f29..271416f 100644 --- a/ToG/freebase_func.py +++ b/ToG/freebase_func.py @@ -33,9 +33,9 @@ def replace_entities_prefix(entities): def id2entity_name_or_type(entity_id): - sparql = sparql_id % (entity_id, entity_id) + entity_id = sparql_id % (entity_id, entity_id) sparql = SPARQLWrapper(SPARQLPATH) - sparql.setQuery(sparql) + sparql.setQuery(entity_id) sparql.setReturnFormat(JSON) results = sparql.query().convert() if len(results["results"]["bindings"])==0: diff --git a/ToG/main_freebase.py b/ToG/main_freebase.py index 47f130d..4664e0c 100644 --- a/ToG/main_freebase.py +++ b/ToG/main_freebase.py @@ -85,7 +85,7 @@ flag_printed = True else: print("depth %d still not find the answer." % depth) - topic_entity = {entity: id2entity_name_or_type[entity] for entity in entities_id} + topic_entity = {entity: id2entity_name_or_type(entity) for entity in entities_id} continue else: half_stop(question, cluster_chain_of_entities, args) diff --git a/ToG/utils.py b/ToG/utils.py index e7f3cdc..b80739a 100644 --- a/ToG/utils.py +++ b/ToG/utils.py @@ -152,7 +152,7 @@ def relation_search_prune(entity_id, entity_name, pre_relations, pre_head, quest if len(pre_relations) != 0 and pre_head !=-1: - tail_relations = [rel for rel in tail_relations if not pre head or rel not in pre_relations] + tail_relations = [rel for rel in tail_relations if not pre_head or rel not in pre_relations] head_relations = [rel for rel in head_relations if pre_head or rel not in pre_relations] head_relations = list(set(head_relations))