diff --git a/structure/cts/amr_ctr/transduction/atomic_extraction.py b/structure/cts/amr_ctr/transduction/atomic_extraction.py index 9e5d5d46d5c820dffca144f1719f8d0a786d2075..f3a69eb826e65ff5e9a7d372f47d8565728d1fd7 100644 --- a/structure/cts/amr_ctr/transduction/atomic_extraction.py +++ b/structure/cts/amr_ctr/transduction/atomic_extraction.py @@ -32,7 +32,7 @@ rule_set['create-atom-class-net'] = { 'comment': "Create Atom Class Net from AMR Term Concept", 'construction': f""" {atom_class_net.construct(base_node='?leaf1', - structure='?sentenceRef', + structure=structure.sentence_ref, class_name='?conceptName')} {atom_class_net.propagate_relations()} @@ -46,9 +46,7 @@ rule_set['create-atom-class-net'] = { ?leaf1Concept rdfs:subClassOf amr:AMR_Term_Concept. ?leaf1Concept amr:label ?conceptName. - # -- Identify structure - ?root a amr:AMR_Root ; - amr:hasSentenceID ?sentenceRef. + {structure.identify()} {atom_class_net.identify_relations_for_propagation('?leaf1')} """, @@ -69,7 +67,7 @@ rule_set['create-individual-net-1'] = { " (2) without link to domain edge"), 'construction': f""" {individual_net.construct(base_node='?baseLeaf', - structure='?sentenceRef', + structure=structure.sentence_ref, mother_class_net='?classNet', individual_label='?valueLabel')} @@ -89,9 +87,7 @@ rule_set['create-individual-net-1'] = { net:coverBaseNode ?baseLeaf ; net:hasClassName ?conceptName. - # -- Identify structure - ?root a amr:AMR_Root ; - amr:hasSentenceID ?sentenceRef. + {structure.identify()} {individual_net.identify_relations_for_propagation('?baseLeaf')} """, @@ -111,7 +107,7 @@ rule_set['create-atom-property-net-1'] = { " (1) from AMR Predicat Concept"), 'construction': f""" {atom_property_net.construct(base_node='?baseLeaf', - structure='?sentenceRef', + structure=structure.sentence_ref, core_role='true', target_argument_node='?argLeaf', property_type='owl:ObjectProperty', @@ -135,9 +131,7 @@ rule_set['create-atom-property-net-1'] = { ?relation amr:hasAmrRole ?someArgRole. }} - # -- Identify structure - ?root a amr:AMR_Root ; - amr:hasSentenceID ?sentenceRef. + {structure.identify()} {atom_property_net.identify_relations_for_propagation('?baseLeaf')} """, @@ -297,7 +291,7 @@ rule_set['create-phenomena-net-1'] = { 'comment': ("Create Phenomena Net from AMR Relation Concept"), 'construction': f""" {phenomena_net.construct(base_node='?baseLeaf', - structure='?sentenceRef', + structure=structure.sentence_ref, core_role='true', target_argument_node='?argLeaf', phenomena_type='?relationConceptPhenomena', @@ -318,9 +312,7 @@ rule_set['create-phenomena-net-1'] = { ?baseLeaf ?relation ?argLeaf. ?relation amr:hasAmrRole ?someArgRole. - # -- Identify structure - ?root a amr:AMR_Root ; - amr:hasSentenceID ?sentenceRef. + {structure.identify()} {phenomena_net.identify_relations_for_propagation('?baseLeaf')} """, @@ -345,7 +337,7 @@ if __name__ == '__main__': test_query_1 = f"""[...] CONSTRUCT {{ {atom_property_net.construct(base_node='?baseLeaf', - structure='?sentenceRef', + structure=structure.sentence_ref, core_role='true', target_argument_node='?argLeaf', property_type='owl:ObjectProperty', @@ -364,7 +356,7 @@ if __name__ == '__main__': {{node1.concept}} amr:label ?conceptName. {{node1.variable}} amr:label ?varLabel. - {{structure.identify()}} + {structure.identify()} {atom_property_net.identify_relations_for_propagation('?baseLeaf')} @@ -379,7 +371,7 @@ if __name__ == '__main__': test_query_2 = f"""[...] CONSTRUCT {{ {individual_net.construct(base_node='?baseLeaf', - structure='?sentenceRef', + structure=structure.sentence_ref, mother_class_net='?classNet', individual_label='?valueLabel')} diff --git a/structure/cts/amr_ctr/transduction/query_builder/builders.py b/structure/cts/amr_ctr/transduction/query_builder/builders.py index ce2c123b2cec4670d9c8d53b97a64f1486e6530a..98afbf32d8444201a25d93cb651fe075a2c29bb5 100644 --- a/structure/cts/amr_ctr/transduction/query_builder/builders.py +++ b/structure/cts/amr_ctr/transduction/query_builder/builders.py @@ -13,6 +13,14 @@ #============================================================================== from .element.net import * +from .element.structure import * + + +#============================================================================== +# AMR Structure Builder(s) +#============================================================================== + +structure = Structure() #============================================================================== diff --git a/structure/cts/amr_ctr/transduction/query_builder/element/structure.py b/structure/cts/amr_ctr/transduction/query_builder/element/structure.py new file mode 100644 index 0000000000000000000000000000000000000000..eb0505ed3064674fb3e3864c2fb87646786e747a --- /dev/null +++ b/structure/cts/amr_ctr/transduction/query_builder/element/structure.py @@ -0,0 +1,123 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Structure Query Builder +#------------------------------------------------------------------------------ +# Class to generate SPARQL query parts related to structure +#============================================================================== + +#============================================================================== +# Importing required modules +#============================================================================== + +# -- + + +#============================================================================== +# Data Repository +#============================================================================== + +# -- Reference Table + +NET_TYPE_TABLE = { # *** [type_name: type_id] *** + 'default': 'Net', + 'atomClass': 'Atom_Class_Net', + 'individual': 'Individual_Net', + 'atomProperty': 'Atom_Property_Net', + 'phenomena': 'Phenomena_Net' + } + +PREDICATE_TABLE = { # *** [attribute_reference: attribute_predicate] *** + 'structure': 'hasStructure', + + 'class_name': 'hasClassName', + + 'mother_class_net': 'hasMotherClassNet', + 'individual_label': 'hasIndividualLabel', + + 'core_role': 'isCoreRoleLinked', + 'target_argument_node': 'targetArgumentNode', + 'property_type': 'hasPropertyType', + 'property_name': 'hasPropertyName', + 'property_name01': 'hasPropertyName01', + 'property_name10': 'hasPropertyName10', + 'property_name12': 'hasPropertyName12', + + 'phenomena_type': 'hasPhenomenaType', + 'phenomena_ref': 'hasPhenomenaRef' + } + +# -- Default Value(s) + +DEFAULT_ATTRIBUTE_VALUE = f'\"NA\"' + + +# -- Useful Constant(s) + +TRIPLE_ENDING_STR = '\n ' + + + +#============================================================================== +# Net Class +#============================================================================== + +class Structure: + """ Class to generate SPARQL query parts related to structure. + """ + + #-------------------------------------------------------------------------- + # Constructor(s) + #-------------------------------------------------------------------------- + + def __init__(self): + + # -- Structure Attribute(s) + self.sentence_ref = f'?sentenceRef' + + + + #-------------------------------------------------------------------------- + # Method(s) to build 'Clause' parts + #-------------------------------------------------------------------------- + + def identify(self): + return f""" + # -- Identify structure + ?root a amr:AMR_Root. + ?root amr:hasSentenceID ?sentenceRef. + """ + + + +#============================================================================== +# Development Test +#============================================================================== + +if __name__ == '__main__': + + print('\n' + ' *** Development Test ***') + + print('\n' + ' -- test: Atom Class Net') + structure = Structure() + print(structure) + + print('\n' + ' -- test: update a test query') + test_query= f"""[...] + CONSTRUCT {{ + [{{atom_class_net.construct('?node1', + structure={structure.sentence_ref}, + class_name='?leaf1ConceptLabel')}} + + }} + WHERE {{ + clause_1 + clause_2 + + {structure.identify()} + }} + """ + print(test_query) + + print('\n' + ' *** - ***') \ No newline at end of file diff --git a/tenet.log b/tenet.log index 701cac7b085b0434970992898a4d55a8a74a748f..b2d8487bb416fdbfe37154bc94e0ef47b30a0e9e 100644 --- a/tenet.log +++ b/tenet.log @@ -66,7 +66,7 @@ - DEBUG - --- Export work graph as turtle - DEBUG - ----- Work graph file: ./output/SolarSystemDev1-20221215/SolarSystemDev1-1/SolarSystemDev1.ttl - DEBUG - --- Ending Structure Preparation -- DEBUG - ----- Total Execution Time = 0:00:00.122984 +- DEBUG - ----- Total Execution Time = 0:00:00.127085 - 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:07.695899 ------ Process Time: 0:00:07.663001 +----- Total Time: 0:00:07.567600 +----- Process Time: 0:00:07.544648 *** - *** - INFO - === Final Ontology Generation === - INFO - -- Making complete factoid graph by merging sentence factoid graphs