From 234a74a8508af9d11c0543e3b1a107a8f2b99184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Lamercerie?= <aurelien.lamercerie@tetras-libre.fr> Date: Wed, 14 Dec 2022 19:04:53 +0100 Subject: [PATCH] Delete old query building module --- .../amr_ctr/transduction/atomic_extraction.py | 14 +- .../transduction/query_builder/binding.py | 66 --------- .../transduction/query_builder/clause.py | 74 ---------- .../transduction/query_builder/construct.py | 128 ------------------ tenet.log | 6 +- 5 files changed, 10 insertions(+), 278 deletions(-) delete mode 100644 structure/cts/amr_ctr/transduction/query_builder/binding.py delete mode 100644 structure/cts/amr_ctr/transduction/query_builder/clause.py delete mode 100644 structure/cts/amr_ctr/transduction/query_builder/construct.py diff --git a/structure/cts/amr_ctr/transduction/atomic_extraction.py b/structure/cts/amr_ctr/transduction/atomic_extraction.py index 69b2bf76..91d3d02e 100644 --- a/structure/cts/amr_ctr/transduction/atomic_extraction.py +++ b/structure/cts/amr_ctr/transduction/atomic_extraction.py @@ -490,19 +490,19 @@ if __name__ == '__main__': print('\n' + ' -- test: update a test query') test_query= f"""[...] CONSTRUCT {{ - {atom_class_net.construct('?node1', - structure='?structureRef', - class_name='?leaf1ConceptLabel')} + {atom_class_net.construct(base_node='{{node1.id}}', + structure='{{structure.sentence_ref}}', + class_name='{{node1.concept_label}}')} {atom_class_net.propagate_relations()} }} WHERE {{ - {{node.identify()}} - ?concept rdfs:subClassOf amr:AMR_Term_Concept. - ?concept amr:label ?conceptName. - ?variable amr:label ?varLabel. + {{node1.identify(type='AMR_Term_Concept')}} + {{node1.concept}} rdfs:subClassOf amr:AMR_Term_Concept. + {{node1.concept}} amr:label ?conceptName. + {{node1.variable}} amr:label ?varLabel. {{structure.identify()}} diff --git a/structure/cts/amr_ctr/transduction/query_builder/binding.py b/structure/cts/amr_ctr/transduction/query_builder/binding.py deleted file mode 100644 index 83973513..00000000 --- a/structure/cts/amr_ctr/transduction/query_builder/binding.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/python3.10 -# -*-coding:Utf-8 -* - -#============================================================================== -# TENET: Binding Query Builder -#------------------------------------------------------------------------------ -# Module offering different functions to build SPARQL queries of transduction -# rules, for binding query part. -#============================================================================== - -#============================================================================== -# Importing required modules -#============================================================================== - -# -- - - -#============================================================================== -# Data Repository -#============================================================================== - -# -- Default References - -DEFAULT_NET_ID = '?newNet' -DEFAULT_NET_TYPE = 'Net' -DEFAULT_SENTENCE_REF = '?sentenceRef' -DEFAULT_BASE_LEAF = '?baseLeaf' -DEFAULT_CLASS_NAME = '?className' - - -# -- Reference Table - -DATA_PROPERTY_TABLE = { - 'sentence_ref': 'hasStructure', - 'class_name': 'hasClassName', - 'mother_class_net': 'hasMotherClassNet', - 'individual_label': 'hasIndividualLabel' - } - - -#============================================================================== -# Useful Functions -#============================================================================== - -# -- - - -#============================================================================== -# Main Functions -#============================================================================== - -def new_variable(id): - return f"*** new_variable(id) ***" - - -#============================================================================== -# Development Test -#============================================================================== - -if __name__ == '__main__': - - print('\n' + ' *** Development Test ***') - - print('\n' + ' -- test: todo') - - print('\n' + ' *** - ***') \ No newline at end of file diff --git a/structure/cts/amr_ctr/transduction/query_builder/clause.py b/structure/cts/amr_ctr/transduction/query_builder/clause.py deleted file mode 100644 index 9281876b..00000000 --- a/structure/cts/amr_ctr/transduction/query_builder/clause.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/python3.10 -# -*-coding:Utf-8 -* - -#============================================================================== -# TENET: Clause Query Builder -#------------------------------------------------------------------------------ -# Module offering different functions to build SPARQL queries of transduction -# rules, for clause query part. -#============================================================================== - -#============================================================================== -# Importing required modules -#============================================================================== - -# -- - - -#============================================================================== -# Data Repository -#============================================================================== - -# -- Default References - -DEFAULT_NET_ID = '?newNet' -DEFAULT_NET_TYPE = 'Net' -DEFAULT_SENTENCE_REF = '?sentenceRef' -DEFAULT_BASE_LEAF = '?baseLeaf' -DEFAULT_CLASS_NAME = '?className' - - -# -- Reference Table - -DATA_PROPERTY_TABLE = { - 'sentence_ref': 'hasStructure', - 'class_name': 'hasClassName', - 'mother_class_net': 'hasMotherClassNet', - 'individual_label': 'hasIndividualLabel' - } - - -#============================================================================== -# Useful Functions -#============================================================================== - -# -- - - -#============================================================================== -# Main Functions -#============================================================================== - -def identify_node(concept, variable): - return f"*** identify_node(concept, variable) ***" - - -def identify_structure(): - return f"*** identify_structure ***" - - -def identify_relations_for_propagation(net_id): - return f"*** identify_relations_for_propagation()***" - - -#============================================================================== -# Development Test -#============================================================================== - -if __name__ == '__main__': - - print('\n' + ' *** Development Test ***') - - print('\n' + ' -- test: todo') - - print('\n' + ' *** - ***') \ No newline at end of file diff --git a/structure/cts/amr_ctr/transduction/query_builder/construct.py b/structure/cts/amr_ctr/transduction/query_builder/construct.py deleted file mode 100644 index b110da1f..00000000 --- a/structure/cts/amr_ctr/transduction/query_builder/construct.py +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/python3.10 -# -*-coding:Utf-8 -* - -#============================================================================== -# TENET: Construct Query Builder -#------------------------------------------------------------------------------ -# Module offering different functions to build SPARQL queries of transduction -# rules, for construct query part. -#============================================================================== - -#============================================================================== -# Importing required modules -#============================================================================== - -# -- - - -#============================================================================== -# Data Repository -#============================================================================== - -# -- Default References - -DEFAULT_NET_ID = '?newNet' -DEFAULT_NET_TYPE = 'Net' -DEFAULT_SENTENCE_REF = '?sentenceRef' -DEFAULT_BASE_LEAF = '?baseLeaf' -DEFAULT_CLASS_NAME = '?className' - - -# -- Reference Table - -DATA_PROPERTY_TABLE = { - 'sentence_ref': 'hasStructure', - 'class_name': 'hasClassName', - 'mother_class_net': 'hasMotherClassNet', - 'individual_label': 'hasIndividualLabel' - } - - -#============================================================================== -# Useful Functions -#============================================================================== - -def get_net_type(net_type): - if not net_type.startswith('net:'): - net_type = f'net:{net_type}' - return net_type - - -def get_data_property(data_ref): - property_name = DATA_PROPERTY_TABLE[f'{data_ref}'] - return f'net:{property_name}' - - -def get_net_data(net_id, **net_data): - data_str = "" - for data_ref, data_val in net_data.items(): - data_property = get_data_property(data_ref) - data_str += f"{net_id} {data_property} {data_val}.\n " - return data_str - - -#============================================================================== -# Main Functions -#============================================================================== - -def new_net(net_id=DEFAULT_NET_ID, - net_type=DEFAULT_NET_TYPE, - base_leaf=DEFAULT_BASE_LEAF, - **net_data ): - - return f""" - # -- New Class Net - {net_id} a {get_net_type(net_type)}. - {net_id} net:coverBaseNode {base_leaf}. - {get_net_data(net_id, **net_data)}""" - - -def relation_propagation(net_id=DEFAULT_NET_ID): - - return f""" - # -- Propagation of relations (from nodes to nets) - ?inRelationRole a net:Relation. - ?inNet ?inRelationRole {net_id}. - ?outRelationRole a net:Relation. - {net_id} ?outRelationRole ?outNet.""" - - -#============================================================================== -# Development Test -#============================================================================== - -if __name__ == '__main__': - - print('\n' + ' *** Development Test ***') - - print('\n' + ' -- test: get_net_data()') - test_str = get_net_data('?newNet', class_name='?conceptName') - print(test_str) - - - print('\n' + ' -- test: new_net') - test_str = new_net(class_name='?conceptName') - print(test_str) - test_str = new_net(net_type='Atom_Class_Net', class_name='?conceptName') - print(test_str) - - print('\n' + ' -- test: update a test query') - test_query= f"""[...] - CONSTRUCT {{ - {new_net(net_type='Atom_Class_Net', - sentence_ref='?sentenceRef', - class_name='?conceptName')} - - {relation_propagation()} - - }} - WHERE {{ - clause_1 - clause_2 - [...] - binding - }} - """ - print(test_query) - - print('\n' + ' *** - ***') \ No newline at end of file diff --git a/tenet.log b/tenet.log index 64071c74..e44734ab 100644 --- a/tenet.log +++ b/tenet.log @@ -66,7 +66,7 @@ - DEBUG - --- Export work graph as turtle - DEBUG - ----- Work graph file: ./output/SolarSystemDev1-20221214/SolarSystemDev1-1/SolarSystemDev1.ttl - DEBUG - --- Ending Structure Preparation -- DEBUG - ----- Total Execution Time = 0:00:00.116396 +- DEBUG - ----- Total Execution Time = 0:00:00.201392 - INFO - -- Loading Extraction Scheme (amr_scheme_1) - DEBUG - ----- Step number: 3 - INFO - -- Loading Extraction Rules (amr_ctr/*) @@ -216,8 +216,8 @@ - INFO - *** Execution Time *** ----- Function: apply (lib.tenet_extraction) ------ Total Time: 0:00:06.149423 ------ Process Time: 0:00:06.139959 +----- Total Time: 0:00:08.164996 +----- Process Time: 0:00:08.033522 *** - *** - INFO - === Final Ontology Generation === - INFO - -- Making complete factoid graph by merging sentence factoid graphs -- GitLab