diff --git a/structure/cts/amr_ctr/transduction/classification.py b/structure/cts/amr_ctr/transduction/classification.py index 4b22aa7249a44911dc25cdd0f0e797b345bce6fd..0f9e2e2a0480e20f076554b91858268d21611bc1 100644 --- a/structure/cts/amr_ctr/transduction/classification.py +++ b/structure/cts/amr_ctr/transduction/classification.py @@ -93,7 +93,7 @@ rule_set['classify-net-from-core-3'] = { ?baseLeaf ?outRelationEdge ?outLeaf. ?outRelationEdge amr:hasAmrRole ?outRelationRole.} """, - 'binding': """ + 'binding': """ # -- New class net BIND (CONCAT(str(net:), 'individual') AS ?n1). BIND (CONCAT(?n1, '_', ?rightConceptName) AS ?n2). @@ -102,62 +102,65 @@ rule_set['classify-net-from-core-3'] = { """ } - -# --- TODO: à revoir --- -# rule_set['classify-net-from-mod'] = { -# 'label': "classify-net-from-mod", -# 'comment': ("Classify Class Net from relations corresponding to: ", -# " Non-Core property :MOD "), -# 'construction': """ -# # -- Entity net -# ?leftClassNet net:hasClassType base-out:Entity. +rule_set['classify-net-from-mod'] = { + 'label': "classify-net-from-mod", + 'comment': ("Classify Class Net from relations corresponding to: ", + " Non-Core property :MOD "), + 'construction': """ + # -- Entity net + ?leftClassNet net:hasClassType base-out:Entity. -# # -- New class net -# ?newNet a net:Individual_Net ; -# net:fromClassNet ?rightClassNet ; -# net:hasStructure ?sentenceRef ; -# net:coverBaseNode ?baseLeaf ; -# net:hasBaseClassName 'Feature' ; -# net:hasIndividualLabel ?rightConceptName. -# ?restrictionNet net:hasRestrictionNetValue ?newNet. + # -- New class net + ?newNet a net:Individual_Net ; + net:fromClassNet ?rightClassNet ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:hasBaseClassName 'Feature' ; + net:hasIndividualLabel ?newClassName. + ?restrictionNet net:hasRestrictionNetValue ?newNet. -# # -- Original net becomes deprecated -# ?rightClassNet net:deprecated true. + # -- Original net becomes deprecated + ?rightClassNet net:deprecated true. -# # -- Propagation of relations (from nodes to nets) -# ?inRelationRole a net:Relation. -# ?inNet ?inRelationRole ?newNet. -# ?outRelationRole a net:Relation. -# ?newNet ?outRelationRole ?outNet. -# """, -# 'clause': """ -# ?leftClassNet a [rdfs:subClassOf* net:Class_Net]. -# ?rightClassNet a [rdfs:subClassOf* net:Class_Net] ; -# net:hasStructure ?sentenceRef ; -# net:coverBaseNode ?baseLeaf ; -# net:hasClassName ?rightConceptName. -# OPTIONAL { ?restrictionNet net:hasRestrictionNetValue ?rightClassNet. } -# ?leftClassNet amr:role_mod ?rightClassNet. + # -- Propagation of relations (from nodes to nets) + ?inRelationRole a net:Relation. + ?inNet ?inRelationRole ?newNet. + ?outRelationRole a net:Relation. + ?newNet ?outRelationRole ?outNet. + """, + 'clause': """ + ?leftClassNet a [rdfs:subClassOf* net:Class_Net]; + net:hasClassName ?leftConceptName. + ?rightClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:hasClassName ?rightConceptName. + OPTIONAL { ?restrictionNet net:hasRestrictionNetValue ?rightClassNet. } + ?leftClassNet amr:role_mod ?rightClassNet. -# # -- 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 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': """ -# BIND (CONCAT(str(net:), 'individual') AS ?n1). -# BIND (CONCAT(?n1, '_', ?rightConceptName) AS ?n2). -# BIND (CONCAT(?n2, '_', 'fromClass') AS ?n3). -# BIND (uri(?n3) AS ?newNet). -# """ -# } + # -- 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 class Name + BIND (CONCAT(?rightConceptName, '-', ?leftConceptName) AS ?newClassName). + + # -- New class net URI + BIND (CONCAT(str(net:), 'individual') AS ?n1). + BIND (CONCAT(?n1, '_', ?newClassName) AS ?n2). + BIND (CONCAT(?n2, '_', 'fromClass') AS ?n3). + BIND (uri(?n3) AS ?newNet). + """ +} rule_set['classify-net-from-part'] = { 'label': "classify-net-from-part", @@ -332,4 +335,30 @@ rule_set['reclassify-deprecated-net'] = { """, 'binding': """ """ -} \ No newline at end of file +} + +#============================================================================== +# Development Test +#============================================================================== + +if __name__ == '__main__': + + print('\n' + ' *** Development Test ***') + + print('\n' + ' -- Test Query') + rule = rule_set['classify-net-from-mod'] + test_query_1 = f"""[...] + CONSTRUCT {{ + {rule['construction']} + + }} + WHERE {{ + {rule['clause']} + + {rule['binding']} + + }} + """ + print(test_query_1) + + print('\n' + ' *** - ***') \ No newline at end of file diff --git a/structure/cts/amr_ctr/transduction/phenomena_application.py b/structure/cts/amr_ctr/transduction/phenomena_application.py index 710b7753516d37b692b3dba54fc59d4acc4475ac..c0d47531c0d65f65f4180e4bb556845988361464 100644 --- a/structure/cts/amr_ctr/transduction/phenomena_application.py +++ b/structure/cts/amr_ctr/transduction/phenomena_application.py @@ -196,10 +196,7 @@ rule_set['and-conjunction-phenomena-application-4'] = { {composite_class_net.construct(base_node=class_net_0.base_node, class_name='?newClassName', mother_class_net=class_net_0.id)} - {composite_class_net.compose(class_net_0.id, property_net.id, logical_set_net.id)} - {composite_class_net.add_attribute(node=class_net_0.node)} - {composite_class_net.add_attribute(node=property_net.base_node)} - {composite_class_net.add_attribute(node=logical_set_net.node)} + {composite_class_net.compose(class_net_0, property_net, logical_set_net)} """, 'clause': f""" # *** Identify Property(arg0:Class, arg1:LogicalSet) *** 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 b0b30269425db2921d0a0c9c63de06a5049673fa..abfe554ce8df63e22291f86bd39a8afbbdae707e 100644 --- a/structure/cts/amr_ctr/transduction/query_builder/element/net.py +++ b/structure/cts/amr_ctr/transduction/query_builder/element/net.py @@ -110,19 +110,6 @@ class Net: predicate = self.__get_track_predicate('progress_step') return f"{self.id} {predicate} {progress_step}." - - def __track_net_composante(self, composante, main=False): - query_code = '' - predicate = self.__get_track_predicate('net_composante') - query_code += f"{self.id} {predicate} {composante}." - if main: - predicate = self.__get_track_predicate('main_net_composante') - query_code += f"\n{INDENT_STR}" - query_code += f"{self.id} {predicate} {composante}." - query_code += f"\n{INDENT_STR}" - return query_code - - def get_progress_step(self, progress_step_ref): predicate = self.__get_track_predicate('progress_step') return f""" @@ -152,6 +139,26 @@ class Net: FILTER (?currentProgressStep < {Net.FINALIZED}).""" return query + + def __track_net_composante(self, composante, main=False): + query_code = '' + predicate = self.__get_track_predicate('net_composante') + query_code += f"{self.id} {predicate} {composante}." + if main: + predicate = self.__get_track_predicate('main_net_composante') + query_code += f"\n{INDENT_STR}" + query_code += f"{self.id} {predicate} {composante}." + query_code += f"\n{INDENT_STR}" + return query_code + + def identify_main_composante(self, target_id): + predicate = self.__get_track_predicate('main_net_composante') + return f"\n{INDENT_STR}{self.id} {predicate} {composante}." + + def identify_composante(self, target_id): + predicate = self.__get_track_predicate('net_composante') + return f"\n{INDENT_STR}{self.id} {predicate} {composante}." + #-------------------------------------------------------------------------- # Method(s) to build 'Construct' parts @@ -163,14 +170,10 @@ class Net: # -- construct triples for attr_ref in self.predicate_table.keys(): - - predicate = self.__get_predicate(attr_ref) - if attr_ref in net_attribute.keys(): - attr_value = net_attribute.get(attr_ref) - comment = '' - - query_code += f"{self.id} {predicate} {attr_value}.{comment}" + predicate = self.__get_predicate(attr_ref) + attr_value = net_attribute.get(attr_ref) + query_code += f"{self.id} {predicate} {attr_value}." query_code += f"\n{INDENT_STR}" return query_code @@ -204,20 +207,17 @@ class Net: def add_attribute(self, **net_attribute): - - query_code = "" - - # -- construct triples with default object for non-declared attributes - for attr_ref in self.predicate_table.keys(): - predicate = self.__get_predicate(attr_ref) - if attr_ref in net_attribute.keys(): - attr_value = net_attribute.get(attr_ref) - query_code += f"{self.id} {predicate} {attr_value}." - query_code += f"\n{INDENT_STR}" - + query_code = self.__define_attribute_triples(**net_attribute) return f""" # -- Additional triple(s) for {self.id} - {query_code}""" + {query_code}""" + + # for attr_ref in self.predicate_table.keys(): + # if attr_ref in net_attribute.keys(): + # predicate = self.__get_predicate(attr_ref) + # attr_value = net_attribute.get(attr_ref) + # query_code += f"{self.id} {predicate} {attr_value}." + # query_code += f"\n{INDENT_STR}" def define_structure(self): @@ -230,19 +230,27 @@ class Net: {query_code}""" def compose(self, *nets): - query_code = f""" - # -- Composition Tracking for {self.id} - """ + query_code = f"\n{INDENT_STR}" + query_code += f'# -- Composition Tracking for {self.id} \n{INDENT_STR}' + main = True - for net_id in nets: + for net in nets: + net_id = f'{net.id}' + net_node = f'{net.node}' query_code += self.__track_net_composante(net_id, main) + query_code += self.__define_attribute_triples(node=net_node) main = False + + if (nets is not None) & (len(nets) != 0): + query_code += f'\n{INDENT_STR}' + query_code += f'# -- Deprecate net \n{INDENT_STR}' + query_code += f'{nets[0].id} a net:Deprecated_Net.\n{INDENT_STR}' return query_code def deprecate(self): return f""" # -- Deprecate net - {self.id} a net:Deprecated_Net.\n{INDENT_STR}""" + """ #-------------------------------------------------------------------------- diff --git a/structure/cts/amr_scheme_1.py b/structure/cts/amr_scheme_1.py index 0f9b63d4730895fae0a204269bf34389bbba7202..b7375651cf063043069121d5d2c8802e5a17ec5f 100644 --- a/structure/cts/amr_scheme_1.py +++ b/structure/cts/amr_scheme_1.py @@ -126,6 +126,23 @@ phenomena_application_sequence = { ] } +InProgressDev_phenomena_application_sequence = { + 'label': 'phenomena-application-sequence', + 'comment': 'Application of phenomena', + 'rule_key_list': ['polarity-phenomena-application', + 'and-conjunction-phenomena-application-1-1', + 'and-conjunction-phenomena-application-1-2', + 'and-conjunction-phenomena-application-2', + 'and-conjunction-phenomena-application-3-1', + 'and-conjunction-phenomena-application-3-2', + 'and-conjunction-phenomena-application-3-3', + 'and-conjunction-phenomena-application-3-4', + 'and-conjunction-phenomena-application-4', + 'and-conjunction-phenomena-application-5', + 'and-conjunction-phenomena-application-6' + ] + } + composite_class_extraction_sequence_1 = { 'label': 'composite-class-extraction-sequence-1', @@ -155,7 +172,7 @@ restriction_adding_sequence = { phenomena_checking_sequence = { 'label': 'phenomena-checking-sequence', 'comment': 'creation of phenomena nets', - 'rule_key_list': [#'expand-and-or-conjunction-phenomena-net', + 'rule_key_list': ['expand-and-or-conjunction-phenomena-net', 'expand-degree-phenomena-net-1', 'expand-degree-phenomena-net-2', 'expand-degree-phenomena-net-3', @@ -181,7 +198,7 @@ classification_sequence = { 'rule_key_list': ['classify-net-from-core-1', 'classify-net-from-core-2', 'classify-net-from-core-3', - # 'classify-net-from-mod', -- TODO: à revoir -- + 'classify-net-from-mod', 'classify-net-from-part', 'classify-net-from-domain', 'classify-net-from-degree-phenomena-1', @@ -236,7 +253,6 @@ scheme = { atomic_extraction_sequence, atomic_extraction_sequence, phenomena_application_sequence, - phenomena_checking_sequence, composite_property_extraction_sequence, composite_class_extraction_sequence_1, composite_class_extraction_sequence_2,