diff --git a/structure/cts/amr_ctr/transduction/atomic_extraction.py b/structure/cts/amr_ctr/transduction/atomic_extraction.py index 91d3d02eb1938d9ef3d2657e28e87ceba0c0bd32..9e5d5d46d5c820dffca144f1719f8d0a786d2075 100644 --- a/structure/cts/amr_ctr/transduction/atomic_extraction.py +++ b/structure/cts/amr_ctr/transduction/atomic_extraction.py @@ -30,20 +30,14 @@ rule_set = {} rule_set['create-atom-class-net'] = { 'label': "create-atom-class-net", 'comment': "Create Atom Class Net from AMR Term Concept", - 'construction': """ - # -- New Class Net - ?newNet a net:Atom_Class_Net ; - net:hasStructure ?sentenceRef ; - net:coverBaseNode ?leaf1 ; - net:hasClassName ?conceptName. + 'construction': f""" + {atom_class_net.construct(base_node='?leaf1', + structure='?sentenceRef', + class_name='?conceptName')} - # -- Propagation of relations (from nodes to nets) - ?inRelationRole a net:Relation. - ?inNet ?inRelationRole ?newNet. - ?outRelationRole a net:Relation. - ?newNet ?outRelationRole ?outNet. + {atom_class_net.propagate_relations()} """, - 'clause': """ + 'clause': f""" # -- Identify Class covering a single leaf ?leaf1 a amr:AMR_Leaf ; amr:hasConcept ?leaf1Concept ; @@ -56,24 +50,10 @@ rule_set['create-atom-class-net'] = { ?root a amr:AMR_Root ; amr:hasSentenceID ?sentenceRef. - # -- Identify inbound relations linked to the base leaf (for propagation) - OPTIONAL {?inNet a [rdfs:subClassOf* net:Net] ; - net:coverBaseNode ?inLeaf. - ?inLeaf ?inRelationEdge ?leaf1. - ?inRelationEdge amr:hasAmrRole ?inRelationRole.} - - # -- Identify outgoing relations linked to the base leaf (for propagation) - OPTIONAL {?outNet a [rdfs:subClassOf* net:Net] ; - net:coverBaseNode ?outLeaf. - ?leaf1 ?outRelationEdge ?outLeaf. - ?outRelationEdge amr:hasAmrRole ?outRelationRole.} + {atom_class_net.identify_relations_for_propagation('?leaf1')} """, - 'binding': """ - # -- New Class Net - BIND (CONCAT(str(net:), 'atomClass') AS ?n1). - BIND (CONCAT(?n1, '_', ?conceptName) AS ?n2). - BIND (CONCAT(?n2, '_', ?varLabel) AS ?n3). - BIND (uri(?n3) AS ?newNet). + 'binding': f""" + {atom_class_net.bind_uri('?conceptName', '?varLabel')} """ } @@ -87,28 +67,22 @@ rule_set['create-individual-net-1'] = { 'comment': ("Create Individual Net from AMR Leaf: ", " (1) with variable corresponding to a named entity ", " (2) without link to domain edge"), - 'construction': """ - # -- New Individual Net - ?newNet a net:Individual_Net ; - net:hasStructure ?sentenceRef ; - net:coverBaseNode ?baseLeaf ; - net:hasMotherClassNet ?classNet ; - net:hasIndividualLabel ?valueLabel. + 'construction': f""" + {individual_net.construct(base_node='?baseLeaf', + structure='?sentenceRef', + mother_class_net='?classNet', + individual_label='?valueLabel')} - # -- Propagation of relations (from nodes to nets) - ?inRelationRole a net:Relation. - ?inNet ?inRelationRole ?newNet. - ?outRelationRole a net:Relation. - ?newNet ?outRelationRole ?outNet. + {individual_net.propagate_relations()} """, - 'clause': """ + 'clause': f""" # -- Identify name relation between a leaf and a value ?baseLeaf a amr:AMR_Leaf ; amr:hasConcept ?concept ; amr:hasVariable ?variable. ?baseLeaf ?edge ?value. ?edge amr:hasRoleID ?roleID. - VALUES ?roleID {'name'} + VALUES ?roleID {{'name'}} ?value a amr:AMR_Value ; rdfs:label ?valueLabel. ?classNet a [rdfs:subClassOf* net:Class_Net] ; @@ -119,89 +93,13 @@ rule_set['create-individual-net-1'] = { ?root a amr:AMR_Root ; amr:hasSentenceID ?sentenceRef. - # -- Identify inbound relations linked to the base leaf (for propagation) - OPTIONAL {?inNet a [rdfs:subClassOf* net:Net] ; - net:coverBaseNode ?inLeaf. - ?inLeaf ?inRelationEdge ?baseLeaf. - ?inRelationEdge amr:hasAmrRole ?inRelationRole.} - - # -- Identify outgoing relations linked to the base leaf (for propagation) - OPTIONAL {?outNet a [rdfs:subClassOf* net:Net] ; - net:coverBaseNode ?outLeaf. - ?baseLeaf ?outRelationEdge ?outLeaf. - ?outRelationEdge amr:hasAmrRole ?outRelationRole.} + {individual_net.identify_relations_for_propagation('?baseLeaf')} """, - 'binding': """ - # -- New Individual Net - BIND (REPLACE(?valueLabel, ' ', "") AS ?valueRef). - BIND (CONCAT(str(net:), 'individual') AS ?n1). - BIND (CONCAT(?n1, '_', ?conceptName) AS ?n2). - BIND (CONCAT(?n2, '_', ?valueRef) AS ?n3). - BIND (uri(?n3) AS ?newNet). + 'binding': f""" + {individual_net.bind_uri('?conceptName', '?valueLabel')} """ } -# -- old --- -# rule_set['create-individual-net-2'] = { -# 'label': "create-individual-net-2", -# 'comment': ("Create Individual Net from AMR Leaf: ", -# " (1) with variable corresponding to a named entity ", -# " (2) with link to domain edge"), -# 'construction': """ -# # -- New Individual Net -# ?newNet a net:Individual_Net ; -# net:hasStructure ?sentenceRef ; -# net:coverBaseNode ?baseLeaf ; -# net:coverArgNode ?rightLeaf ; -# net:hasMotherClassNet ?leftClassNet ; -# net:hasIndividualLabel ?varNameLabel. - -# # -- Propagation of relations (from nodes to nets) -# ?inRelationRole a net:Relation. -# ?inNet ?inRelationRole ?newNet. -# ?outRelationRole a net:Relation. -# ?newNet ?outRelationRole ?outNet. -# """, -# 'clause': """ -# # -- Identify individual covering leaf with domain relation -# ?leftClassNet a [rdfs:subClassOf* net:Class_Net] ; -# net:coverBaseNode ?baseLeaf ; -# net:hasClassName ?leftConceptName. -# ?rightLeaf a amr:AMR_Leaf ; -# amr:hasConcept ?rightConcept ; -# amr:hasVariable ?rightVariable. -# ?baseLeaf ?roleEdge ?rightLeaf. -# ?roleEdge amr:hasAmrRole amr:role_domain. -# ?leftVariable amr:label ?leftVariableLabel. -# ?rightVariable amr:name ?rightVariableName. -# ?rightVariableName rdfs:label ?varNameLabel. - -# # -- Identify structure -# ?root a amr:AMR_Root ; -# amr:hasSentenceID ?sentenceRef. - -# # -- Identify inbound relations linked to the base leaf (for propagation) -# OPTIONAL {?inNet a [rdfs:subClassOf* net:Net] ; -# net:coverBaseNode ?inLeaf. -# ?inLeaf ?inRelationEdge ?baseLeaf. -# ?inRelationEdge amr:hasAmrRole ?inRelationRole.} - -# # -- Identify outgoing relations linked to the base leaf (for propagation) -# OPTIONAL {?outNet a [rdfs:subClassOf* net:Net] ; -# net:coverBaseNode ?outLeaf. -# ?baseLeaf ?outRelationEdge ?outLeaf. -# ?outRelationEdge amr:hasAmrRole ?outRelationRole.} -# """, -# 'binding': """ -# # -- New Individual Net -# BIND (CONCAT(str(net:), 'individual') AS ?n1). -# BIND (CONCAT(?n1, '_', ?leftConceptName) AS ?n2). -# BIND (CONCAT(?n2, '_', ?leftVariableLabel) AS ?n3). -# BIND (uri(?n3) AS ?newNet). -# """ -# } -# -- --- - # --------------------------------------------- # Atomic Extraction: Property Net @@ -211,26 +109,20 @@ rule_set['create-atom-property-net-1'] = { 'label': "create-atom-property-net-1", 'comment': ("Create Atom Property Net: ", " (1) from AMR Predicat Concept"), - 'construction': """ - # -- New Property Net - ?newNet a net:Atom_Property_Net ; - net:isCoreRoleLinked true ; - net:hasStructure ?sentenceRef ; - net:coverBaseNode ?baseLeaf ; - net:targetArgumentNode ?argLeaf ; - net:hasPropertyType owl:ObjectProperty ; - net:hasPropertyName ?propertyName ; - net:hasPropertyName01 ?propertyName01 ; - net:hasPropertyName10 ?propertyName10 ; - net:hasPropertyName12 ?propertyName12. - - # -- Propagation of relations (from nodes to nets) - ?inRelationRole a net:Relation. - ?inNet ?inRelationRole ?newNet. - ?outRelationRole a net:Relation. - ?newNet ?outRelationRole ?outNet. + 'construction': f""" + {atom_property_net.construct(base_node='?baseLeaf', + structure='?sentenceRef', + core_role='true', + target_argument_node='?argLeaf', + property_type='owl:ObjectProperty', + property_name='?propertyName', + property_name01='?propertyName01', + property_name10='?propertyName10', + property_name12='?propertyName12')} + + {atom_property_net.propagate_relations()} """, - 'clause': """ + 'clause': f""" # -- Identify property covering single leaf ?baseLeaf a amr:AMR_Leaf ; amr:hasConcept ?concept ; @@ -238,26 +130,18 @@ rule_set['create-atom-property-net-1'] = { ?variable amr:label ?varLabel. ?concept rdfs:subClassOf amr:AMR_Predicat_Concept ; amr:label ?predicateLabel. - OPTIONAL {?baseLeaf ?relation ?argLeaf. - ?relation amr:hasAmrRole ?someArgRole.} + OPTIONAL {{ + ?baseLeaf ?relation ?argLeaf. + ?relation amr:hasAmrRole ?someArgRole. + }} # -- Identify structure ?root a amr:AMR_Root ; amr:hasSentenceID ?sentenceRef. - # -- Identify inbound relations linked to the base leaf (for propagation) - OPTIONAL {?inNet a [rdfs:subClassOf* net:Net] ; - net:coverBaseNode ?inLeaf. - ?inLeaf ?inRelationEdge ?baseLeaf. - ?inRelationEdge amr:hasAmrRole ?inRelationRole.} - - # -- Identify outgoing relations linked to the base leaf (for propagation) - OPTIONAL {?outNet a [rdfs:subClassOf* net:Net] ; - net:coverBaseNode ?outLeaf. - ?baseLeaf ?outRelationEdge ?outLeaf. - ?outRelationEdge amr:hasAmrRole ?outRelationRole.} + {atom_property_net.identify_relations_for_propagation('?baseLeaf')} """, - 'binding': """ + 'binding': f""" BIND (STRBEFORE(?predicateLabel, '-') AS ?pName1). BIND (IF (STRLEN(?pName1) > 0, ?pName1, ?predicateLabel) AS ?propertyName) @@ -268,17 +152,7 @@ rule_set['create-atom-property-net-1'] = { BIND (IF (STRLEN(?pName1) > 0, CONCAT(?propertyName, '-of'), ?predicateLabel) AS ?propertyName12) - # -- New Property Name - # -- old --- BIND (STRBEFORE(?predicateLabel, '-') AS ?propertyName). - # -- old --- BIND (CONCAT(?propertyName, 'ing') AS ?propertyName01). - # -- old --- BIND (CONCAT(?propertyName, '-by') AS ?propertyName10). - # -- old --- BIND (CONCAT(?propertyName, '-of') AS ?propertyName12). - - # -- New Property Net - BIND (CONCAT(str(net:), 'atomProperty') AS ?n1). - BIND (CONCAT(?n1, '_', ?propertyName) AS ?n2). - BIND (CONCAT(?n2, '_', ?varLabel) AS ?n3). - BIND (uri(?n3) AS ?newNet). + {atom_property_net.bind_uri('?propertyName', '?varLabel')} """ } @@ -287,7 +161,7 @@ rule_set['create-atom-property-net-1'] = { # 'label': "create-atom-property-net-2", # 'comment': ("Create Property Net from AMR Predicat Concept: ", # " with variable corresponding to a negative polarity value "), -# 'construction': """ +# 'construction': f""" # # -- New Property Net # ?newNet a net:Atom_Property_Net ; # net:isCoreRoleLinked true ; @@ -335,7 +209,7 @@ rule_set['create-atom-property-net-1'] = { # ?baseLeaf ?outRelationEdge ?outLeaf. # ?outRelationEdge amr:hasAmrRole ?outRelationRole.} # """, -# 'binding': """ +# 'binding': f""" # # -- New Property Name # BIND (STRBEFORE(?predicateLabel, '-') AS ?basePropertyName). # BIND (CONCAT('not-', ?basePropertyName) AS ?propertyName). @@ -357,7 +231,7 @@ rule_set['create-atom-property-net-1'] = { # 'label': "create-atom-property-net-3", # 'comment': ("Create Atom Property Net: ", # " (1) from AMR Non Core Role Edge"), -# 'construction': """ +# 'construction': f""" # # -- New Property Net # ?newNet a net:Atom_Property_Net ; # net:isCoreRoleLinked false ; @@ -403,7 +277,7 @@ rule_set['create-atom-property-net-1'] = { # ?baseLeaf ?outRelationEdge ?outLeaf. # ?outRelationEdge amr:hasAmrRole ?outRelationRole.} # """, -# 'binding': """ +# 'binding': f""" # # -- New Property Net # BIND (CONCAT(str(net:), 'atomProperty') AS ?n1). # BIND (CONCAT(?n1, '_', str(?roleName)) AS ?n2). @@ -421,23 +295,17 @@ rule_set['create-atom-property-net-1'] = { rule_set['create-phenomena-net-1'] = { 'label': "create-phenomena-net-1", 'comment': ("Create Phenomena Net from AMR Relation Concept"), - 'construction': """ - # -- New Phenomena Net - ?newNet a net:Phenomena_Net ; - net:isCoreRoleLinked true ; - net:hasStructure ?sentenceRef ; - net:coverBaseNode ?baseLeaf ; - net:targetArgumentNode ?argLeaf ; - net:hasPhenomenaType ?relationConceptPhenomena ; - net:hasPhenomenaRef ?relationConceptLabel. - - # -- Propagation of relations (from nodes to nets) - ?inRelationRole a net:Relation. - ?inNet ?inRelationRole ?newNet. - ?outRelationRole a net:Relation. - ?newNet ?outRelationRole ?outNet. + 'construction': f""" + {phenomena_net.construct(base_node='?baseLeaf', + structure='?sentenceRef', + core_role='true', + target_argument_node='?argLeaf', + phenomena_type='?relationConceptPhenomena', + phenomena_ref='?relationConceptLabel')} + + {phenomena_net.propagate_relations()} """, - 'clause': """ + 'clause': f""" # Identify relation concept (phenomena) covering a single leaf ?baseLeaf a amr:AMR_Leaf ; amr:hasConcept ?concept ; @@ -454,24 +322,10 @@ rule_set['create-phenomena-net-1'] = { ?root a amr:AMR_Root ; amr:hasSentenceID ?sentenceRef. - # -- Identify inbound relations linked to the base leaf (for propagation) - OPTIONAL {?inNet a [rdfs:subClassOf* net:Net] ; - net:coverBaseNode ?inLeaf. - ?inLeaf ?inRelationEdge ?baseLeaf. - ?inRelationEdge amr:hasAmrRole ?inRelationRole.} - - # -- Identify outgoing relations linked to the base leaf (for propagation) - OPTIONAL {?outNet a [rdfs:subClassOf* net:Net] ; - net:coverBaseNode ?outLeaf. - ?baseLeaf ?outRelationEdge ?outLeaf. - ?outRelationEdge amr:hasAmrRole ?outRelationRole.} + {phenomena_net.identify_relations_for_propagation('?baseLeaf')} """, - 'binding': """ - # -- New Phenomena Net - BIND (CONCAT(str(net:), 'phenomena') AS ?n1). - BIND (CONCAT(?n1, '_', ?phenomenaLabel) AS ?n2). - BIND (CONCAT(?n2, '_', ?varLabel) AS ?n3). - BIND (uri(?n3) AS ?newNet). + 'binding': f""" + {phenomena_net.bind_uri('?phenomenaLabel', '?varLabel')} """ } @@ -487,14 +341,20 @@ if __name__ == '__main__': print('\n' + ' -- test: Atom Class Net') print(atom_class_net) - print('\n' + ' -- test: update a test query') - test_query= f"""[...] + print('\n' + ' -- test: update a test query (1)') + test_query_1 = f"""[...] CONSTRUCT {{ - {atom_class_net.construct(base_node='{{node1.id}}', - structure='{{structure.sentence_ref}}', - class_name='{{node1.concept_label}}')} + {atom_property_net.construct(base_node='?baseLeaf', + structure='?sentenceRef', + core_role='true', + target_argument_node='?argLeaf', + property_type='owl:ObjectProperty', + property_name='?propertyName', + property_name01='?propertyName01', + property_name10='?propertyName10', + property_name12='?propertyName12')} - {atom_class_net.propagate_relations()} + {atom_property_net.propagate_relations()} }} @@ -506,12 +366,32 @@ if __name__ == '__main__': {{structure.identify()}} - {{atom_class_net.identify_relations_for_propagation()}} + {atom_property_net.identify_relations_for_propagation('?baseLeaf')} - {{atom_class_net.bind_uri()}} + {atom_property_net.bind_uri('{{node1.concept_label}}', + '{{node1.variable_label}}')} }} """ - print(test_query) + print(test_query_1) + + print('\n' + ' -- test: update a test query (2)') + test_query_2 = f"""[...] + CONSTRUCT {{ + {individual_net.construct(base_node='?baseLeaf', + structure='?sentenceRef', + mother_class_net='?classNet', + individual_label='?valueLabel')} + + + + }} + WHERE {{ + + + }} + """ + print(test_query_2) + print('\n' + ' *** - ***') diff --git a/structure/cts/amr_ctr/transduction/query_builder/builders.py b/structure/cts/amr_ctr/transduction/query_builder/builders.py index 34471634859468fd8cf1ac5d93bc9d6e79a40bc4..ce2c123b2cec4670d9c8d53b97a64f1486e6530a 100644 --- a/structure/cts/amr_ctr/transduction/query_builder/builders.py +++ b/structure/cts/amr_ctr/transduction/query_builder/builders.py @@ -20,9 +20,18 @@ from .element.net import * #============================================================================== # -- Atom Class Net -atom_class_net = Net('atomClassNet', 'Atom_Class_Net') -atom_class_net_1 = Net('atomClassNet1', 'Atom_Class_Net') -atom_class_net_2 = Net('atomClassNet2', 'Atom_Class_Net') +atom_class_net = Net('atomClass') +atom_class_net_1 = Net('atomClass', 1) +atom_class_net_2 = Net('atomClass', 2) + +# -- Individual Net +individual_net = Net('individual') + +# -- Atom Property Net +atom_property_net = Net('atomProperty') + +# -- Phenomena Net +phenomena_net = Net('phenomena') #============================================================================== diff --git a/structure/cts/amr_ctr/transduction/query_builder/element/net.py b/structure/cts/amr_ctr/transduction/query_builder/element/net.py index 794f509e337d70f23d32f40e20c5fd6332c47558..e97d2c8ab2fb8bb04fba79fb0c763b18406b0819 100644 --- a/structure/cts/amr_ctr/transduction/query_builder/element/net.py +++ b/structure/cts/amr_ctr/transduction/query_builder/element/net.py @@ -18,27 +18,49 @@ # 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 = { +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' - } + '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 ' + #============================================================================== -# Class +# Net Class #============================================================================== class Net: @@ -49,48 +71,69 @@ class Net: # Constructor(s) #-------------------------------------------------------------------------- - def __init__(self, id='defaultNetId', type='Net'): + def __init__(self, type_name='default', num=''): # -- Net Signature - self.id = f'?{id}' - self.type = f'net:{type}' - self.base_node = f'?{id}BaseNode' + self.id = f'?{type_name}Net{num}' + self.type_name = type_name + self.type_uri = f'net:{NET_TYPE_TABLE[type_name]}' - # -- Net Data - self.structure = f'?{id}Structure' - self.class_name = f'?{id}ClassName' - self.mother_class_net = f'?{id}MotherClassNet' - self.individual_label = f'?{id}IndividualLabel' + # -- Net Attributes + self.base_node = f'{self.id}BaseNode' + self.structure = f'{self.id}Structure' + self.class_name = f'{self.id}ClassName' + self.mother_class_net = f'{self.id}MotherClassNet' + self.individual_label = f'{self.id}IndividualLabel' # -- Private elements (for relation propagation) - self._in_relation_role = f'?{id}InRelationRole' - self._in_net = f'?{id}InNet' - self._out_relation_role = f'?{id}OutRelationRole' - self._out_net = f'?{id}OutNet' + self._in_relation_role = f'{self.id}InRelationRole' + self._in_net = f'{self.id}InNet' + self._out_relation_role = f'{self.id}OutRelationRole' + self._out_net = f'{self.id}OutNet' #-------------------------------------------------------------------------- - # Construct Method(s) + # Private data accessor(s) #-------------------------------------------------------------------------- - def __get_data_property(self, data_ref): - property_name = DATA_PROPERTY_TABLE[f'{data_ref}'] + def __get_predicate(self, data_ref): + property_name = PREDICATE_TABLE[f'{data_ref}'] return f'net:{property_name}' + + #-------------------------------------------------------------------------- + # Method(s) to build 'Construct' parts + #-------------------------------------------------------------------------- + + def __construct_attribute_triples(self, **net_attribute): + + result_triples = "" + + # -- construct triples with declared attributes + for attr_ref, attr_value in net_attribute.items(): + predicate = self.__get_predicate(attr_ref) + result_triples += f"{self.id} {predicate} {attr_value}." + result_triples += f"{TRIPLE_ENDING_STR}" + + # -- construct triples with default object for non-declared attributes + result_triples += f"# *** default values for attribute useless *** " + result_triples += f"{TRIPLE_ENDING_STR}" + for attr_ref in PREDICATE_TABLE.keys(): + if attr_ref not in net_attribute.keys(): + predicate = self.__get_predicate(attr_ref) + result_triples += f"{self.id} {predicate} {DEFAULT_ATTRIBUTE_VALUE}." + result_triples += f"{TRIPLE_ENDING_STR}" + + return result_triples - def __get_net_data(self, **net_data): - data_str = "" - for data_ref, data_val in net_data.items(): - data_property = self.__get_data_property(data_ref) - data_str += f"{self.id} {data_property} {data_val}.\n " - return data_str - def construct(self, base_node, **net_data): + def construct(self, base_node, **net_attribute): return f""" - # -- New Class Net - {self.id} a {self.type}. + # -- New Net + {self.id} a {self.type_uri}. {self.id} net:coverBaseNode {base_node}. - {self.__get_net_data(**net_data)}""" + {self.__construct_attribute_triples(**net_attribute)}""" + def propagate_relations(self): return f""" @@ -103,16 +146,48 @@ class Net: #-------------------------------------------------------------------------- - # Method(s) to get the SPARQL query corresponding to the rule + # Method(s) to build 'Clause' parts #-------------------------------------------------------------------------- + def identify_relations_for_propagation(self, base_node): + return f""" + # -- Identify inbound relations linked to the base leaf (for propagation) + OPTIONAL {{ + {self._in_net} a [rdfs:subClassOf* net:Net] ; + net:coverBaseNode ?inLeaf. + ?inLeaf ?inRelationEdge {base_node}. + ?inRelationEdge amr:hasAmrRole {self._in_relation_role}. + }} + + # -- Identify outgoing relations linked to the base leaf (for propagation) + OPTIONAL {{ + {self._out_net} a [rdfs:subClassOf* net:Net] ; + net:coverBaseNode ?outLeaf. + {base_node} ?outRelationEdge ?outLeaf. + ?outRelationEdge amr:hasAmrRole {self._out_relation_role}. + }} + """ #-------------------------------------------------------------------------- - # Method(s) to update a graph by running the rule SPARQL query + # Method(s) to build 'Binding' parts #-------------------------------------------------------------------------- + def bind_uri(self, net_name='nameless', node_reference='00'): + ref1 = f"{self.id}Ref1" + ref2 = f"{self.id}Ref2" + ref3 = f"{self.id}Ref3" + refNet = f"{net_name}RefNet" + refNode = f"{node_reference}RefNode" + return f""" + # -- New Net + BIND (REPLACE({net_name}, ' ', "") AS {refNet}). + BIND (REPLACE({node_reference}, ' ', "") AS {refNode}). + BIND (CONCAT(str(net:), '{self.type_name}') AS {ref1}). + BIND (CONCAT({ref1}, '_', {refNet}) AS {ref2}). + BIND (CONCAT({ref2}, '_', {refNode}) AS {ref3}). + BIND (uri({ref3}) AS {self.id}).""" @@ -125,7 +200,7 @@ if __name__ == '__main__': print('\n' + ' *** Development Test ***') print('\n' + ' -- test: Atom Class Net') - atom_class_net = Net('atomClassNet', 'Atom_Class_Net') + atom_class_net = Net('atomClass') print(atom_class_net) @@ -148,8 +223,11 @@ if __name__ == '__main__': WHERE {{ clause_1 clause_2 - [...] - binding + + {atom_class_net.identify_relations_for_propagation('?node1')} + + {atom_class_net.bind_uri('{{node1.concept_label}}', + '{{node1.variable_label}}')} }} """ print(test_query) diff --git a/tenet.log b/tenet.log index e44734ab248c43ba49711b5a3d789b58b214d084..701cac7b085b0434970992898a4d55a8a74a748f 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-20221214/ - ----- sentence output directory: ./output/SolarSystemDev1-20221214/ + ----- output directory: ./output/SolarSystemDev1-20221215/ + ----- sentence output directory: ./output/SolarSystemDev1-20221215/ ----- 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-20221214/SolarSystemDev1.ttl + ----- output file: ./output/SolarSystemDev1-20221215/SolarSystemDev1.ttl *** - *** -- INFO - -- Creating output target directory: ./output/SolarSystemDev1-20221214/ +- INFO - -- Creating output target directory: ./output/SolarSystemDev1-20221215/ - 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-20221214/SolarSystemDev1-1/SolarSystemDev1.ttl +- DEBUG - ----- Work graph file: ./output/SolarSystemDev1-20221215/SolarSystemDev1-1/SolarSystemDev1.ttl - DEBUG - --- Ending Structure Preparation -- DEBUG - ----- Total Execution Time = 0:00:00.201392 +- DEBUG - ----- Total Execution Time = 0:00:00.122984 - INFO - -- Loading Extraction Scheme (amr_scheme_1) - DEBUG - ----- Step number: 3 - INFO - -- Loading Extraction Rules (amr_ctr/*) @@ -95,133 +95,133 @@ - DEBUG - --- Serializing graph to SolarSystemDev1_preprocessing - DEBUG - ----- step: preprocessing - DEBUG - ----- id: SolarSystemDev1 -- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221214/SolarSystemDev1-1/SolarSystemDev1_preprocessing.ttl +- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221215/SolarSystemDev1-1/SolarSystemDev1_preprocessing.ttl - DEBUG - ----- base: http://SolarSystemDev1/preprocessing - INFO - ----- 212 triples extracted during preprocessing step - INFO - -- Applying extraction step: transduction - INFO - --- Sequence: atomic-extraction-sequence -- INFO - ----- create-atom-class-net: 20/20 new triples (846) -- DEBUG - ----- (refinement) refine-cover-node-1: 5 new triples (851) -- DEBUG - ----- (refinement) refine-cover-node-2: 5 new triples (856) -- INFO - ----- create-individual-net-1: 7/7 new triples (863) -- DEBUG - ----- (refinement) refine-cover-node-1: 1 new triples (864) -- INFO - ----- create-atom-property-net-1: 69/69 new triples (933) -- DEBUG - ----- (refinement) refine-cover-node-1: 6 new triples (939) -- INFO - ----- create-phenomena-net-1: 24/25 new triples (963) -- DEBUG - ----- (refinement) refine-cover-node-1: 2 new triples (965) +- INFO - ----- create-atom-class-net: 75/75 new triples (901) +- DEBUG - ----- (refinement) refine-cover-node-1: 5 new triples (906) +- DEBUG - ----- (refinement) refine-cover-node-2: 5 new triples (911) +- INFO - ----- create-individual-net-1: 17/17 new triples (928) +- DEBUG - ----- (refinement) refine-cover-node-1: 1 new triples (929) +- INFO - ----- create-atom-property-net-1: 99/99 new triples (1028) +- DEBUG - ----- (refinement) refine-cover-node-1: 6 new triples (1034) +- INFO - ----- create-phenomena-net-1: 40/41 new triples (1074) +- DEBUG - ----- (refinement) refine-cover-node-1: 2 new triples (1076) - INFO - --- Sequence: atomic-extraction-sequence -- INFO - ----- create-atom-class-net: 1/34 new triples (966) -- DEBUG - ----- create-individual-net-1: 0/7 new triples (966) -- INFO - ----- create-atom-property-net-1: 1/76 new triples (967) -- DEBUG - ----- create-phenomena-net-1: 0/25 new triples (967) +- INFO - ----- create-atom-class-net: 1/89 new triples (1077) +- DEBUG - ----- create-individual-net-1: 0/17 new triples (1077) +- INFO - ----- create-atom-property-net-1: 1/106 new triples (1078) +- DEBUG - ----- create-phenomena-net-1: 0/41 new triples (1078) - INFO - --- Sequence: phenomena-checking-sequence -- INFO - ----- expand-and-conjunction-phenomena-net: 4/4 new triples (971) -- DEBUG - ----- expand-degree-phenomena-net-1: 0/0 new triples (971) -- DEBUG - ----- expand-degree-phenomena-net-2: 0/0 new triples (971) -- DEBUG - ----- expand-degree-phenomena-net-3: 0/0 new triples (971) -- DEBUG - ----- expand-degree-phenomena-net-4: 0/0 new triples (971) -- DEBUG - ----- expand-degree-phenomena-net-5: 0/0 new triples (971) -- DEBUG - ----- expand-degree-phenomena-net-6: 0/0 new triples (971) +- INFO - ----- expand-and-conjunction-phenomena-net: 4/4 new triples (1082) +- DEBUG - ----- expand-degree-phenomena-net-1: 0/0 new triples (1082) +- DEBUG - ----- expand-degree-phenomena-net-2: 0/0 new triples (1082) +- DEBUG - ----- expand-degree-phenomena-net-3: 0/0 new triples (1082) +- DEBUG - ----- expand-degree-phenomena-net-4: 0/0 new triples (1082) +- DEBUG - ----- expand-degree-phenomena-net-5: 0/0 new triples (1082) +- DEBUG - ----- expand-degree-phenomena-net-6: 0/0 new triples (1082) - INFO - --- Sequence: composite-property-extraction-sequence -- DEBUG - ----- create-composite-class-net-from-property-1: 0/0 new triples (971) -- DEBUG - ----- create-composite-class-net-from-property-2: 0/0 new triples (971) +- DEBUG - ----- create-composite-class-net-from-property-1: 0/0 new triples (1082) +- DEBUG - ----- create-composite-class-net-from-property-2: 0/0 new triples (1082) - INFO - --- Sequence: composite-class-extraction-sequence-1 -- INFO - ----- create-composite-class-net-from-property-1: 75/79 new triples (1046) -- DEBUG - ----- (refinement) refine-cover-node-1: 12 new triples (1058) -- DEBUG - ----- (refinement) refine-cover-node-2: 4 new triples (1062) -- DEBUG - ----- create-composite-class-net-from-property-2: 0/0 new triples (1062) -- DEBUG - ----- create-composite-class-net-from-property-3: 0/0 new triples (1062) +- INFO - ----- create-composite-class-net-from-property-1: 75/79 new triples (1157) +- DEBUG - ----- (refinement) refine-cover-node-1: 12 new triples (1169) +- DEBUG - ----- (refinement) refine-cover-node-2: 4 new triples (1173) +- DEBUG - ----- create-composite-class-net-from-property-2: 0/0 new triples (1173) +- DEBUG - ----- create-composite-class-net-from-property-3: 0/0 new triples (1173) - INFO - --- Sequence: composite-class-extraction-sequence-2 -- DEBUG - ----- create-composite-class-net-from-phenomena-1: 0/0 new triples (1062) -- DEBUG - ----- create-composite-class-net-from-phenomena-2: 0/0 new triples (1062) -- DEBUG - ----- create-composite-class-net-from-phenomena-3: 0/0 new triples (1062) -- DEBUG - ----- create-composite-class-net-from-phenomena-4: 0/0 new triples (1062) +- DEBUG - ----- create-composite-class-net-from-phenomena-1: 0/0 new triples (1173) +- DEBUG - ----- create-composite-class-net-from-phenomena-2: 0/0 new triples (1173) +- DEBUG - ----- create-composite-class-net-from-phenomena-3: 0/0 new triples (1173) +- DEBUG - ----- create-composite-class-net-from-phenomena-4: 0/0 new triples (1173) - INFO - --- Sequence: phenomena-checking-sequence -- INFO - ----- expand-and-conjunction-phenomena-net: 1/5 new triples (1063) -- DEBUG - ----- expand-degree-phenomena-net-1: 0/0 new triples (1063) -- DEBUG - ----- expand-degree-phenomena-net-2: 0/0 new triples (1063) -- DEBUG - ----- expand-degree-phenomena-net-3: 0/0 new triples (1063) -- DEBUG - ----- expand-degree-phenomena-net-4: 0/0 new triples (1063) -- DEBUG - ----- expand-degree-phenomena-net-5: 0/0 new triples (1063) -- DEBUG - ----- expand-degree-phenomena-net-6: 0/0 new triples (1063) +- INFO - ----- expand-and-conjunction-phenomena-net: 1/5 new triples (1174) +- DEBUG - ----- expand-degree-phenomena-net-1: 0/0 new triples (1174) +- DEBUG - ----- expand-degree-phenomena-net-2: 0/0 new triples (1174) +- DEBUG - ----- expand-degree-phenomena-net-3: 0/0 new triples (1174) +- DEBUG - ----- expand-degree-phenomena-net-4: 0/0 new triples (1174) +- DEBUG - ----- expand-degree-phenomena-net-5: 0/0 new triples (1174) +- DEBUG - ----- expand-degree-phenomena-net-6: 0/0 new triples (1174) - INFO - --- Sequence: composite-property-extraction-sequence -- DEBUG - ----- create-composite-class-net-from-property-1: 0/0 new triples (1063) -- DEBUG - ----- create-composite-class-net-from-property-2: 0/0 new triples (1063) +- DEBUG - ----- create-composite-class-net-from-property-1: 0/0 new triples (1174) +- DEBUG - ----- create-composite-class-net-from-property-2: 0/0 new triples (1174) - INFO - --- Sequence: composite-class-extraction-sequence-1 -- INFO - ----- create-composite-class-net-from-property-1: 94/173 new triples (1157) -- DEBUG - ----- (refinement) refine-cover-node-1: 15 new triples (1172) -- DEBUG - ----- (refinement) refine-cover-node-2: 5 new triples (1177) -- DEBUG - ----- create-composite-class-net-from-property-2: 0/0 new triples (1177) -- DEBUG - ----- create-composite-class-net-from-property-3: 0/0 new triples (1177) +- INFO - ----- create-composite-class-net-from-property-1: 94/173 new triples (1268) +- DEBUG - ----- (refinement) refine-cover-node-1: 15 new triples (1283) +- DEBUG - ----- (refinement) refine-cover-node-2: 5 new triples (1288) +- DEBUG - ----- create-composite-class-net-from-property-2: 0/0 new triples (1288) +- DEBUG - ----- create-composite-class-net-from-property-3: 0/0 new triples (1288) - INFO - --- Sequence: composite-class-extraction-sequence-2 -- DEBUG - ----- create-composite-class-net-from-phenomena-1: 0/0 new triples (1177) -- DEBUG - ----- create-composite-class-net-from-phenomena-2: 0/0 new triples (1177) -- DEBUG - ----- create-composite-class-net-from-phenomena-3: 0/0 new triples (1177) -- DEBUG - ----- create-composite-class-net-from-phenomena-4: 0/0 new triples (1177) +- DEBUG - ----- create-composite-class-net-from-phenomena-1: 0/0 new triples (1288) +- DEBUG - ----- create-composite-class-net-from-phenomena-2: 0/0 new triples (1288) +- DEBUG - ----- create-composite-class-net-from-phenomena-3: 0/0 new triples (1288) +- DEBUG - ----- create-composite-class-net-from-phenomena-4: 0/0 new triples (1288) - INFO - --- Sequence: restriction-adding-sequence -- DEBUG - ----- add-restriction-to-class-net-from-property-1: 0/0 new triples (1177) +- DEBUG - ----- add-restriction-to-class-net-from-property-1: 0/0 new triples (1288) - INFO - --- Sequence: classification-sequence -- INFO - ----- classify-net-from-core-1: 12/12 new triples (1189) -- INFO - ----- classify-net-from-core-2: 1/9 new triples (1190) -- DEBUG - ----- classify-net-from-core-3: 0/0 new triples (1190) -- DEBUG - ----- classify-net-from-mod: 0/0 new triples (1190) -- DEBUG - ----- classify-net-from-part: 0/0 new triples (1190) -- INFO - ----- classify-net-from-domain: 6/6 new triples (1196) -- DEBUG - ----- classify-net-from-degree-phenomena-1: 0/0 new triples (1196) -- DEBUG - ----- classify-net-from-degree-phenomena-2: 0/0 new triples (1196) -- DEBUG - ----- classify-net-from-degree-phenomena-3: 0/0 new triples (1196) -- DEBUG - ----- propagate-individual-1: 0/1 new triples (1196) -- INFO - ----- propagate-individual-2: 6/6 new triples (1202) -- DEBUG - ----- reclassify-deprecated-net: 0/0 new triples (1202) +- INFO - ----- classify-net-from-core-1: 12/12 new triples (1300) +- INFO - ----- classify-net-from-core-2: 1/9 new triples (1301) +- DEBUG - ----- classify-net-from-core-3: 0/0 new triples (1301) +- DEBUG - ----- classify-net-from-mod: 0/0 new triples (1301) +- DEBUG - ----- classify-net-from-part: 0/0 new triples (1301) +- INFO - ----- classify-net-from-domain: 6/6 new triples (1307) +- DEBUG - ----- classify-net-from-degree-phenomena-1: 0/0 new triples (1307) +- DEBUG - ----- classify-net-from-degree-phenomena-2: 0/0 new triples (1307) +- DEBUG - ----- classify-net-from-degree-phenomena-3: 0/0 new triples (1307) +- DEBUG - ----- propagate-individual-1: 0/1 new triples (1307) +- INFO - ----- propagate-individual-2: 6/6 new triples (1313) +- DEBUG - ----- reclassify-deprecated-net: 0/0 new triples (1313) - DEBUG - --- Serializing graph to SolarSystemDev1_transduction - DEBUG - ----- step: transduction - DEBUG - ----- id: SolarSystemDev1 -- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221214/SolarSystemDev1-1/SolarSystemDev1_transduction.ttl +- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221215/SolarSystemDev1-1/SolarSystemDev1_transduction.ttl - DEBUG - ----- base: http://SolarSystemDev1/transduction -- INFO - ----- 376 triples extracted during transduction step +- INFO - ----- 487 triples extracted during transduction step - INFO - -- Applying extraction step: generation - INFO - --- Sequence: main-generation-sequence -- INFO - ----- compute-uri-for-owl-declaration-1: 14/14 new triples (1216) -- INFO - ----- compute-uri-for-owl-declaration-2: 1/1 new triples (1217) -- DEBUG - ----- compute-uri-for-owl-declaration-4: 0/0 new triples (1217) -- INFO - ----- compute-uri-for-owl-declaration-5: 6/6 new triples (1223) -- INFO - ----- compute-uri-for-owl-declaration-6: 6/6 new triples (1229) -- INFO - ----- generate-atom-class: 12/12 new triples (1241) -- INFO - ----- classify-atom-class-1: 4/4 new triples (1245) -- INFO - ----- classify-atom-class-2: 1/1 new triples (1246) -- INFO - ----- generate-individual: 3/3 new triples (1249) -- INFO - ----- classify-individual: 6/6 new triples (1255) -- INFO - ----- generate-atom-property-1: 20/20 new triples (1275) -- INFO - ----- generate-atom-property-12: 12/20 new triples (1287) -- DEBUG - ----- generate-inverse-relation: 0/0 new triples (1287) -- INFO - ----- generate-composite-class: 38/38 new triples (1325) -- DEBUG - ----- add-restriction-to-class-1: 0/0 new triples (1325) -- DEBUG - ----- add-restriction-to-class-2: 0/0 new triples (1325) -- INFO - ----- add-restriction-to-class-3: 36/45 new triples (1361) -- DEBUG - ----- add-restriction-to-class-4: 0/0 new triples (1361) -- DEBUG - ----- add-restriction-to-class-5: 0/0 new triples (1361) -- DEBUG - ----- add-restriction-to-class-6: 0/0 new triples (1361) -- DEBUG - ----- generate-composite-property: 0/0 new triples (1361) +- INFO - ----- compute-uri-for-owl-declaration-1: 14/14 new triples (1327) +- INFO - ----- compute-uri-for-owl-declaration-2: 1/1 new triples (1328) +- DEBUG - ----- compute-uri-for-owl-declaration-4: 0/0 new triples (1328) +- INFO - ----- compute-uri-for-owl-declaration-5: 6/6 new triples (1334) +- INFO - ----- compute-uri-for-owl-declaration-6: 6/6 new triples (1340) +- INFO - ----- generate-atom-class: 12/12 new triples (1352) +- INFO - ----- classify-atom-class-1: 4/4 new triples (1356) +- INFO - ----- classify-atom-class-2: 1/1 new triples (1357) +- INFO - ----- generate-individual: 3/3 new triples (1360) +- INFO - ----- classify-individual: 6/6 new triples (1366) +- INFO - ----- generate-atom-property-1: 20/20 new triples (1386) +- INFO - ----- generate-atom-property-12: 12/20 new triples (1398) +- DEBUG - ----- generate-inverse-relation: 0/0 new triples (1398) +- INFO - ----- generate-composite-class: 38/38 new triples (1436) +- DEBUG - ----- add-restriction-to-class-1: 0/0 new triples (1436) +- DEBUG - ----- add-restriction-to-class-2: 0/0 new triples (1436) +- INFO - ----- add-restriction-to-class-3: 36/45 new triples (1472) +- DEBUG - ----- add-restriction-to-class-4: 0/0 new triples (1472) +- DEBUG - ----- add-restriction-to-class-5: 0/0 new triples (1472) +- DEBUG - ----- add-restriction-to-class-6: 0/0 new triples (1472) +- DEBUG - ----- generate-composite-property: 0/0 new triples (1472) - DEBUG - --- Serializing graph to SolarSystemDev1_generation - DEBUG - ----- step: generation - DEBUG - ----- id: SolarSystemDev1 -- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221214/SolarSystemDev1-1/SolarSystemDev1_generation.ttl +- DEBUG - ----- work_file: ./output/SolarSystemDev1-20221215/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-20221214/SolarSystemDev1-1/SolarSystemDev1_factoid.ttl) +- DEBUG - --- Serializing graph to factoid file (./output/SolarSystemDev1-20221215/SolarSystemDev1-1/SolarSystemDev1_factoid.ttl) - INFO - *** Execution Time *** ----- Function: apply (lib.tenet_extraction) ------ Total Time: 0:00:08.164996 ------ Process Time: 0:00:08.033522 +----- Total Time: 0:00:07.695899 +----- Process Time: 0:00:07.663001 *** - *** - 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-20221214/SolarSystemDev1_factoid.ttl) +- INFO - -- Serializing graph to factoid file (./output/SolarSystemDev1-20221215/SolarSystemDev1_factoid.ttl) - INFO - === Done ===