diff --git a/lib/transduction/binding_query_builder.py b/lib/transduction/binding_query_builder.py new file mode 100644 index 0000000000000000000000000000000000000000..8397351353bf54c2e33e5b7477cb454e37228633 --- /dev/null +++ b/lib/transduction/binding_query_builder.py @@ -0,0 +1,66 @@ +#!/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/lib/transduction/clause_query_builder.py b/lib/transduction/clause_query_builder.py new file mode 100644 index 0000000000000000000000000000000000000000..9281876ba842a6a0774988e1446a9ab3176b1e17 --- /dev/null +++ b/lib/transduction/clause_query_builder.py @@ -0,0 +1,74 @@ +#!/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/lib/transduction/construct_query_builder.py b/lib/transduction/construct_query_builder.py index b4a5303285a5466f5e7d77fbd5cd49ea62fb3d17..e916fcd989fd2546b72b64622422f1ee24aa90a8 100644 --- a/lib/transduction/construct_query_builder.py +++ b/lib/transduction/construct_query_builder.py @@ -12,14 +12,15 @@ # Importing required modules #============================================================================== - +# -- #============================================================================== -# Global Variable +# Data Repository #============================================================================== # -- Default References + DEFAULT_NET_ID = '?newNet' DEFAULT_NET_TYPE = 'Net' DEFAULT_SENTENCE_REF = '?sentenceRef' @@ -27,15 +28,16 @@ DEFAULT_BASE_LEAF = '?baseLeaf' DEFAULT_CLASS_NAME = '?className' -#============================================================================== -# Useful Functions -#============================================================================== +# -- Reference Table DATA_PROPERTY_TABLE = { - 'sentence_ref': 'net:hasStructure', - 'class_name': 'net:hasClassName' + 'sentence_ref': 'hasStructure', + 'class_name': 'hasClassName', + 'mother_class_net': 'hasMotherClassNet', + 'individual_label': 'hasIndividualLabel' } + #============================================================================== # Useful Functions #============================================================================== @@ -44,12 +46,17 @@ 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 = DATA_PROPERTY_TABLE[f'{data_ref}'] + data_property = get_data_property(data_ref) data_str += f"{net_id} {data_property} {data_val}.\n " return data_str diff --git a/lib/transduction/query_builder.py b/lib/transduction/query_builder.py new file mode 100644 index 0000000000000000000000000000000000000000..4fe3d2f02560697f9344f1ae53046d7920a46908 --- /dev/null +++ b/lib/transduction/query_builder.py @@ -0,0 +1,82 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Query Builder +#------------------------------------------------------------------------------ +# Module to build SPARQL queries of transduction rules, using some specific +# builder for different query parts. +#============================================================================== + +#============================================================================== +# Importing required modules +#============================================================================== + +import construct_query_builder as construct +import clause_query_builder as clause +import binding_query_builder as binding + + + +#============================================================================== +# Data Repository +#============================================================================== + +# -- + + +#============================================================================== +# Useful Functions +#============================================================================== + +# -- + + +#============================================================================== +# Main Functions +#============================================================================== + +# -- + + +#============================================================================== +# Development Test +#============================================================================== + +if __name__ == '__main__': + + print('\n' + ' *** Development Test ***') + + print('\n' + ' -- test: new_net') + test_str = construct.new_net(class_name='?conceptName') + print(test_str) + + print('\n' + ' -- test: update a test query') + test_query= f"""[...] + CONSTRUCT {{ + {construct.new_net(net_id='?newNet1', + net_type='Atom_Class_Net', + sentence_ref='?sentenceRef', + class_name='?conceptName')} + + {construct.relation_propagation(net_id='?newNet1')} + + + }} + WHERE {{ + {clause.identify_node('?concept', '?variable')} + ?concept rdfs:subClassOf amr:AMR_Term_Concept. + ?concept amr:label ?conceptName. + ?variable amr:label ?varLabel. + + {clause.identify_structure()} + + {clause.identify_relations_for_propagation(net_id='?newNet1')} + + {binding.new_variable('?newNet1')} + + }} + """ + print(test_query) + + print('\n' + ' *** - ***') \ No newline at end of file