Skip to content
Snippets Groups Projects
Commit 824bc2ff authored by Aurélien Lamercerie's avatar Aurélien Lamercerie
Browse files

Init dev for module construct query builder

parent 1b5e9eb2
No related branches found
No related tags found
No related merge requests found
#!/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
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
----- CTS directory: ./structure/cts/ ----- CTS directory: ./structure/cts/
----- target frame directory: ./input/targetFrameStructure/ ----- target frame directory: ./input/targetFrameStructure/
----- input document directory: ./input/amrDocuments/ ----- input document directory: ./input/amrDocuments/
----- output directory: ./output/SolarSystemDev1-20221210/ ----- output directory: ./output/SolarSystemDev1-20221212/
----- sentence output directory: ./output/SolarSystemDev1-20221210/ ----- sentence output directory: ./output/SolarSystemDev1-20221212/
----- SHACL binary directory: ./lib/shacl-1.3.2/bin ----- SHACL binary directory: ./lib/shacl-1.3.2/bin
-- Config File Definition -- Config File Definition
----- schema file: ./structure/amr-rdf-schema.ttl ----- schema file: ./structure/amr-rdf-schema.ttl
...@@ -44,9 +44,9 @@ ...@@ -44,9 +44,9 @@
----- frame ontology seed file: ./input/targetFrameStructure/base-ontology-seed.ttl ----- frame ontology seed file: ./input/targetFrameStructure/base-ontology-seed.ttl
-- Output -- Output
----- ontology namespace: https://tenet.tetras-libre.fr/base-ontology/ ----- 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 - -- Counting number of graph files (sentences)
- DEBUG - ----- Graph count: 1 - DEBUG - ----- Graph count: 1
- INFO - === Extraction Processing using New TENET Engine === - INFO - === Extraction Processing using New TENET Engine ===
...@@ -64,9 +64,9 @@ ...@@ -64,9 +64,9 @@
- DEBUG - ----- Sentence Loading - DEBUG - ----- Sentence Loading
- DEBUG - -------- ./input/amrDocuments/dev/solar-system-1/SSC-01-01.stog.amr.ttl (614) - DEBUG - -------- ./input/amrDocuments/dev/solar-system-1/SSC-01-01.stog.amr.ttl (614)
- DEBUG - --- Export work graph as turtle - 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 - --- 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) - INFO - -- Loading Extraction Scheme (amr_scheme_1)
- DEBUG - ----- Step number: 3 - DEBUG - ----- Step number: 3
- INFO - -- Loading Extraction Rules (amr_ctr/*) - INFO - -- Loading Extraction Rules (amr_ctr/*)
...@@ -95,7 +95,7 @@ ...@@ -95,7 +95,7 @@
- DEBUG - --- Serializing graph to SolarSystemDev1_preprocessing - DEBUG - --- Serializing graph to SolarSystemDev1_preprocessing
- DEBUG - ----- step: preprocessing - DEBUG - ----- step: preprocessing
- DEBUG - ----- id: SolarSystemDev1 - 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 - DEBUG - ----- base: http://SolarSystemDev1/preprocessing
- INFO - ----- 212 triples extracted during preprocessing step - INFO - ----- 212 triples extracted during preprocessing step
- INFO - -- Applying extraction step: transduction - INFO - -- Applying extraction step: transduction
...@@ -176,7 +176,7 @@ ...@@ -176,7 +176,7 @@
- DEBUG - --- Serializing graph to SolarSystemDev1_transduction - DEBUG - --- Serializing graph to SolarSystemDev1_transduction
- DEBUG - ----- step: transduction - DEBUG - ----- step: transduction
- DEBUG - ----- id: SolarSystemDev1 - 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 - DEBUG - ----- base: http://SolarSystemDev1/transduction
- INFO - ----- 376 triples extracted during transduction step - INFO - ----- 376 triples extracted during transduction step
- INFO - -- Applying extraction step: generation - INFO - -- Applying extraction step: generation
...@@ -205,23 +205,23 @@ ...@@ -205,23 +205,23 @@
- DEBUG - --- Serializing graph to SolarSystemDev1_generation - DEBUG - --- Serializing graph to SolarSystemDev1_generation
- DEBUG - ----- step: generation - DEBUG - ----- step: generation
- DEBUG - ----- id: SolarSystemDev1 - 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 - DEBUG - ----- base: http://SolarSystemDev1/generation
- INFO - ----- 159 triples extracted during generation step - INFO - ----- 159 triples extracted during generation step
- INFO - -- Result: file containing only the factoids - INFO - -- Result: file containing only the factoids
- DEBUG - --- Making factoid graph with the last step result - DEBUG - --- Making factoid graph with the last step result
- DEBUG - ----- Number of factoids: 176 - DEBUG - ----- Number of factoids: 176
- DEBUG - ----- Graph base: http://SolarSystemDev1/factoid - 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 - - INFO -
*** Execution Time *** *** Execution Time ***
----- Function: apply (lib.tenet_extraction) ----- Function: apply (lib.tenet_extraction)
----- Total Time: 0:00:07.319353 ----- Total Time: 0:00:09.171347
----- Process Time: 0:00:07.293875 ----- Process Time: 0:00:09.035147
*** - *** *** - ***
- INFO - === Final Ontology Generation === - INFO - === Final Ontology Generation ===
- INFO - -- Making complete factoid graph by merging sentence factoid graphs - INFO - -- Making complete factoid graph by merging sentence factoid graphs
- INFO - ----- Total factoid number: 176 - INFO - ----- Total factoid number: 176
- INFO - ----- Graph base: http://SolarSystemDev1/factoid - 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 === - INFO - === Done ===
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment