diff --git a/lib/transduction/construct_query_builder.py b/lib/transduction/construct_query_builder.py new file mode 100644 index 0000000000000000000000000000000000000000..b4a5303285a5466f5e7d77fbd5cd49ea62fb3d17 --- /dev/null +++ b/lib/transduction/construct_query_builder.py @@ -0,0 +1,120 @@ +#!/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 +#============================================================================== + + + + +#============================================================================== +# Global Variable +#============================================================================== + +# -- Default References +DEFAULT_NET_ID = '?newNet' +DEFAULT_NET_TYPE = 'Net' +DEFAULT_SENTENCE_REF = '?sentenceRef' +DEFAULT_BASE_LEAF = '?baseLeaf' +DEFAULT_CLASS_NAME = '?className' + + +#============================================================================== +# Useful Functions +#============================================================================== + +DATA_PROPERTY_TABLE = { + 'sentence_ref': 'net:hasStructure', + 'class_name': 'net:hasClassName' + } + +#============================================================================== +# 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_net_data(net_id, **net_data): + data_str = "" + for data_ref, data_val in net_data.items(): + data_property = DATA_PROPERTY_TABLE[f'{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 521c7b2468019453eba921130e6bb9c5f848ca2f..e3e5ce6b5b6392248fc29ce5a7c857f616bdda86 100644 --- a/tenet.log +++ b/tenet.log @@ -23,8 +23,8 @@ ----- CTS directory: ./structure/cts/ ----- target frame directory: ./input/targetFrameStructure/ ----- input document directory: ./input/amrDocuments/ - ----- output directory: ./output/SolarSystemDev1-20221210/ - ----- sentence output directory: ./output/SolarSystemDev1-20221210/ + ----- output directory: ./output/SolarSystemDev1-20221212/ + ----- sentence output directory: ./output/SolarSystemDev1-20221212/ ----- SHACL binary directory: ./lib/shacl-1.3.2/bin -- Config File Definition ----- schema file: ./structure/amr-rdf-schema.ttl @@ -44,9 +44,9 @@ ----- frame ontology seed file: ./input/targetFrameStructure/base-ontology-seed.ttl -- Output ----- ontology namespace: https://tenet.tetras-libre.fr/base-ontology/ - ----- output file: ./output/SolarSystemDev1-20221210/SolarSystemDev1.ttl + ----- output file: ./output/SolarSystemDev1-20221212/SolarSystemDev1.ttl *** - *** -- INFO - -- Creating output target directory: ./output/SolarSystemDev1-20221210/ +- INFO - -- Creating output target directory: ./output/SolarSystemDev1-20221212/ - DEBUG - -- Counting number of graph files (sentences) - DEBUG - ----- Graph count: 1 - INFO - === Extraction Processing using New TENET Engine === @@ -64,9 +64,9 @@ - DEBUG - ----- Sentence Loading - DEBUG - -------- ./input/amrDocuments/dev/solar-system-1/SSC-01-01.stog.amr.ttl (614) - DEBUG - --- Export work graph as turtle -- DEBUG - ----- Work graph file: ./output/SolarSystemDev1-20221210/SolarSystemDev1-1/SolarSystemDev1.ttl +- DEBUG - ----- Work graph file: ./output/SolarSystemDev1-20221212/SolarSystemDev1-1/SolarSystemDev1.ttl - DEBUG - --- Ending Structure Preparation -- DEBUG - ----- Total Execution Time = 0:00:00.120758 +- DEBUG - ----- Total Execution Time = 0:00:00.155235 - INFO - -- Loading Extraction Scheme (amr_scheme_1) - DEBUG - ----- Step number: 3 - INFO - -- Loading Extraction Rules (amr_ctr/*) @@ -95,7 +95,7 @@ - DEBUG - --- Serializing graph to SolarSystemDev1_preprocessing - DEBUG - ----- step: preprocessing - DEBUG - ----- id: SolarSystemDev1 -- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221210/SolarSystemDev1-1/SolarSystemDev1_preprocessing.ttl +- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221212/SolarSystemDev1-1/SolarSystemDev1_preprocessing.ttl - DEBUG - ----- base: http://SolarSystemDev1/preprocessing - INFO - ----- 212 triples extracted during preprocessing step - INFO - -- Applying extraction step: transduction @@ -176,7 +176,7 @@ - DEBUG - --- Serializing graph to SolarSystemDev1_transduction - DEBUG - ----- step: transduction - DEBUG - ----- id: SolarSystemDev1 -- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221210/SolarSystemDev1-1/SolarSystemDev1_transduction.ttl +- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221212/SolarSystemDev1-1/SolarSystemDev1_transduction.ttl - DEBUG - ----- base: http://SolarSystemDev1/transduction - INFO - ----- 376 triples extracted during transduction step - INFO - -- Applying extraction step: generation @@ -205,23 +205,23 @@ - DEBUG - --- Serializing graph to SolarSystemDev1_generation - DEBUG - ----- step: generation - DEBUG - ----- id: SolarSystemDev1 -- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221210/SolarSystemDev1-1/SolarSystemDev1_generation.ttl +- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221212/SolarSystemDev1-1/SolarSystemDev1_generation.ttl - DEBUG - ----- base: http://SolarSystemDev1/generation - INFO - ----- 159 triples extracted during generation step - INFO - -- Result: file containing only the factoids - DEBUG - --- Making factoid graph with the last step result - DEBUG - ----- Number of factoids: 176 - DEBUG - ----- Graph base: http://SolarSystemDev1/factoid -- DEBUG - --- Serializing graph to factoid file (./output/SolarSystemDev1-20221210/SolarSystemDev1-1/SolarSystemDev1_factoid.ttl) +- DEBUG - --- Serializing graph to factoid file (./output/SolarSystemDev1-20221212/SolarSystemDev1-1/SolarSystemDev1_factoid.ttl) - INFO - *** Execution Time *** ----- Function: apply (lib.tenet_extraction) ------ Total Time: 0:00:07.319353 ------ Process Time: 0:00:07.293875 +----- Total Time: 0:00:09.171347 +----- Process Time: 0:00:09.035147 *** - *** - INFO - === Final Ontology Generation === - INFO - -- Making complete factoid graph by merging sentence factoid graphs - INFO - ----- Total factoid number: 176 - INFO - ----- Graph base: http://SolarSystemDev1/factoid -- INFO - -- Serializing graph to factoid file (./output/SolarSystemDev1-20221210/SolarSystemDev1_factoid.ttl) +- INFO - -- Serializing graph to factoid file (./output/SolarSystemDev1-20221212/SolarSystemDev1_factoid.ttl) - INFO - === Done ===