diff --git a/tenet/config.xml b/tenet/config.xml index 5e0047c7c9046ac08b705fb476f36a34b37660d6..ea98399c2cca82d6e5d6416f260e9f1d9d533034 100644 --- a/tenet/config.xml +++ b/tenet/config.xml @@ -7,7 +7,7 @@ /> <cts - amr_cts_ref = "amr_scheme_1" + amr_cts_ref = "amr_scheme_clara_1" unl_cts_ref = "unl_scheme_1" /> @@ -24,7 +24,7 @@ <file amr_input_data_schema = "amr-rdf-schema" unl_input_data_schema = "unl-rdf-schema" - semantic_net_schema = "semantic-net" + semantic_net_schema = "odrl-snet-schema" config_param = "config-parameters" /> diff --git a/tenet/scheme/amr_clara_rule/__init__.py b/tenet/scheme/amr_clara_rule/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ef58bb6e27abbee73044368f774088c8e6a023 --- /dev/null +++ b/tenet/scheme/amr_clara_rule/__init__.py @@ -0,0 +1,21 @@ +from scheme.amr_clara_rule.preprocessing.amr_reification import * +from scheme.amr_clara_rule.preprocessing.amrld_correcting import * + +from scheme.amr_clara_rule.transduction.atom_class_extractor import * +from scheme.amr_clara_rule.transduction.atom_individual_extractor import * +from scheme.amr_clara_rule.transduction.atom_property_extractor import * +from scheme.amr_clara_rule.transduction.atom_value_extractor import * +from scheme.amr_clara_rule.transduction.atom_phenomena_extractor import * +from scheme.amr_clara_rule.transduction.atom_relation_propagator import * + +from scheme.amr_clara_rule.transduction.composite_class_extractor_1 import * +from scheme.amr_clara_rule.transduction.composite_class_extractor_2 import * + +from scheme.amr_clara_rule.transduction.phenomena_polarity_analyzer_1 import * +from scheme.amr_clara_rule.transduction.phenomena_mod_analyzer_1 import * +from scheme.amr_clara_rule.transduction.phenomena_or_analyzer_1 import * +from scheme.amr_clara_rule.transduction.phenomena_or_analyzer_2 import * + +from scheme.amr_clara_rule.odrl_generation.odrl_rule_generator import * + +from scheme.amr_clara_rule import * diff --git a/tenet/scheme/amr_rule/__rule_pattern.py b/tenet/scheme/amr_clara_rule/__rule_pattern.py similarity index 100% rename from tenet/scheme/amr_rule/__rule_pattern.py rename to tenet/scheme/amr_clara_rule/__rule_pattern.py diff --git a/tenet/scheme/amr_rule/nov_generation.py b/tenet/scheme/amr_clara_rule/nov_generation.py similarity index 100% rename from tenet/scheme/amr_rule/nov_generation.py rename to tenet/scheme/amr_clara_rule/nov_generation.py diff --git a/tenet/scheme/amr_rule/generation/__init__.py b/tenet/scheme/amr_clara_rule/nov_transduction/__init__.py similarity index 100% rename from tenet/scheme/amr_rule/generation/__init__.py rename to tenet/scheme/amr_clara_rule/nov_transduction/__init__.py diff --git a/tenet/scheme/amr_rule/nov_transduction/atomic_extraction.py b/tenet/scheme/amr_clara_rule/nov_transduction/atomic_extraction.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/atomic_extraction.py rename to tenet/scheme/amr_clara_rule/nov_transduction/atomic_extraction.py diff --git a/tenet/scheme/amr_rule/nov_transduction/classification.py b/tenet/scheme/amr_clara_rule/nov_transduction/classification.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/classification.py rename to tenet/scheme/amr_clara_rule/nov_transduction/classification.py diff --git a/tenet/scheme/amr_rule/nov_transduction/composite_class_extraction_1.py b/tenet/scheme/amr_clara_rule/nov_transduction/composite_class_extraction_1.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/composite_class_extraction_1.py rename to tenet/scheme/amr_clara_rule/nov_transduction/composite_class_extraction_1.py diff --git a/tenet/scheme/amr_rule/nov_transduction/composite_class_extraction_2.py b/tenet/scheme/amr_clara_rule/nov_transduction/composite_class_extraction_2.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/composite_class_extraction_2.py rename to tenet/scheme/amr_clara_rule/nov_transduction/composite_class_extraction_2.py diff --git a/tenet/scheme/amr_rule/nov_transduction/composite_property_extraction.py b/tenet/scheme/amr_clara_rule/nov_transduction/composite_property_extraction.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/composite_property_extraction.py rename to tenet/scheme/amr_clara_rule/nov_transduction/composite_property_extraction.py diff --git a/tenet/scheme/amr_rule/nov_transduction/phenomena_application_and.py b/tenet/scheme/amr_clara_rule/nov_transduction/phenomena_application_and.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/phenomena_application_and.py rename to tenet/scheme/amr_clara_rule/nov_transduction/phenomena_application_and.py diff --git a/tenet/scheme/amr_rule/nov_transduction/phenomena_application_mod.py b/tenet/scheme/amr_clara_rule/nov_transduction/phenomena_application_mod.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/phenomena_application_mod.py rename to tenet/scheme/amr_clara_rule/nov_transduction/phenomena_application_mod.py diff --git a/tenet/scheme/amr_rule/nov_transduction/phenomena_application_polarity.py b/tenet/scheme/amr_clara_rule/nov_transduction/phenomena_application_polarity.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/phenomena_application_polarity.py rename to tenet/scheme/amr_clara_rule/nov_transduction/phenomena_application_polarity.py diff --git a/tenet/scheme/amr_rule/nov_transduction/phenomena_checking.py b/tenet/scheme/amr_clara_rule/nov_transduction/phenomena_checking.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/phenomena_checking.py rename to tenet/scheme/amr_clara_rule/nov_transduction/phenomena_checking.py diff --git a/tenet/scheme/amr_rule/nov_transduction/technical_ctr.py b/tenet/scheme/amr_clara_rule/nov_transduction/technical_ctr.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/technical_ctr.py rename to tenet/scheme/amr_clara_rule/nov_transduction/technical_ctr.py diff --git a/tenet/scheme/amr_rule/nov_transduction/__init__.py b/tenet/scheme/amr_clara_rule/odrl_generation/__init__.py similarity index 100% rename from tenet/scheme/amr_rule/nov_transduction/__init__.py rename to tenet/scheme/amr_clara_rule/odrl_generation/__init__.py diff --git a/tenet/scheme/amr_clara_rule/odrl_generation/odrl_rule_generator.py b/tenet/scheme/amr_clara_rule/odrl_generation/odrl_rule_generator.py new file mode 100644 index 0000000000000000000000000000000000000000..b86851d84095f443f151896c0db22dcdf218ba70 --- /dev/null +++ b/tenet/scheme/amr_clara_rule/odrl_generation/odrl_rule_generator.py @@ -0,0 +1,100 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to conjunctive phenomena or (rule 1) +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to analyse conjunctive phenomena (or) +# Rule: property(class, or_phenomena) => compositeClass +#============================================================================== + +import rdflib +from rdflib import Graph +from rdflib.namespace import FOAF, RDF + +import transduction +from transduction import net +from transduction.rdfterm_computer import produce_uriref, produce_literal +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_axiom_naming +from transduction.naming_computer import define_composite_naming_2 + + +#============================================================================== +# Pattern Search: Rule and Action Nets +#============================================================================== + +def __search_pattern_1(graph): + select_data_list = ['?rule_net'] + clause_list = [(f'?rule_net a net:Rule_Net.')] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +def __search_pattern_2(graph): + select_data_list = ['?action_net'] + clause_list = [(f'?action_net a net:Action_Net.')] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Check Methods +#============================================================================== + +def __is_property_to_generate(property_net): + check_1 = property_net.is_deprecated() + if is_instance(property_net.mother_property_net, list): + check_2 = len(property_net.mother_property_net) > 0 + else: + check_2 = False + return not check_1 or check_2 + + + +#============================================================================== +# Generator Methods +#============================================================================== + +def __compute_policy_uri(graph, net): + return produce_uriref(graph, f'ext-out:policy_{net.structure}') + + +def __compute_odrl_rule_type_uri(graph, net): + odrl_rule_type_uri = f'odrl:permission' + # TODO: odrl:permission, odrl;obligation, odrl:prohibition + return produce_uriref(graph, odrl_rule_type_uri) + + +def __generate_odrl_triple_definition(graph, net): + policy_uri = __compute_policy_uri(graph, net) + odrl_rule_type_uri = __compute_odrl_rule_type_uri(graph, net) + action_definition = produce_literal(graph, 'net:x') + # print(f'{policy_uri}, {odrl_rule_type_uri}, {action_definition}') + return [(policy_uri, odrl_rule_type_uri, action_definition)] + + + +#============================================================================== +# Main Method: analyze_phenomena_or_1 +#============================================================================== + +def generate_odrl_rule(graph): + + # -- Rule Initialization + rule_label = 'generate ODRL rule' + rule_triple_list = [] + + # -- Get property net listings + _, pattern_set = __search_pattern_1(graph) + + # # -- Triple Definition for 'not deprecated property net' + for pattern in pattern_set: + rule_net = net.RuleNet(graph, pattern.rule_net) + if not rule_net.is_deprecated(): + rule_triple_list += __generate_odrl_triple_definition(graph, rule_net) + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_rule/preprocessing/__init__.py b/tenet/scheme/amr_clara_rule/owl_generation/__init__.py similarity index 100% rename from tenet/scheme/amr_rule/preprocessing/__init__.py rename to tenet/scheme/amr_clara_rule/owl_generation/__init__.py diff --git a/tenet/scheme/amr_rule/generation/owl_property_generator.py b/tenet/scheme/amr_clara_rule/owl_generation/owl_property_generator.py similarity index 100% rename from tenet/scheme/amr_rule/generation/owl_property_generator.py rename to tenet/scheme/amr_clara_rule/owl_generation/owl_property_generator.py diff --git a/tenet/scheme/amr_rule/preprocessing.py b/tenet/scheme/amr_clara_rule/preprocessing.py similarity index 100% rename from tenet/scheme/amr_rule/preprocessing.py rename to tenet/scheme/amr_clara_rule/preprocessing.py diff --git a/tenet/scheme/amr_rule/transduction/__init__.py b/tenet/scheme/amr_clara_rule/preprocessing/__init__.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/__init__.py rename to tenet/scheme/amr_clara_rule/preprocessing/__init__.py diff --git a/tenet/scheme/amr_rule/preprocessing/amr_reification.py b/tenet/scheme/amr_clara_rule/preprocessing/amr_reification.py similarity index 100% rename from tenet/scheme/amr_rule/preprocessing/amr_reification.py rename to tenet/scheme/amr_clara_rule/preprocessing/amr_reification.py diff --git a/tenet/scheme/amr_rule/preprocessing/amrld_correcting.py b/tenet/scheme/amr_clara_rule/preprocessing/amrld_correcting.py similarity index 100% rename from tenet/scheme/amr_rule/preprocessing/amrld_correcting.py rename to tenet/scheme/amr_clara_rule/preprocessing/amrld_correcting.py diff --git a/tenet/scheme/amr_clara_rule/transduction/__init__.py b/tenet/scheme/amr_clara_rule/transduction/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..8d1c8b69c3fce7bea45c73efd06983e3c419a92f --- /dev/null +++ b/tenet/scheme/amr_clara_rule/transduction/__init__.py @@ -0,0 +1 @@ + diff --git a/tenet/scheme/amr_rule/transduction/atom_class_extractor.py b/tenet/scheme/amr_clara_rule/transduction/atom_class_extractor.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/atom_class_extractor.py rename to tenet/scheme/amr_clara_rule/transduction/atom_class_extractor.py diff --git a/tenet/scheme/amr_rule/transduction/atom_individual_extractor.py b/tenet/scheme/amr_clara_rule/transduction/atom_individual_extractor.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/atom_individual_extractor.py rename to tenet/scheme/amr_clara_rule/transduction/atom_individual_extractor.py diff --git a/tenet/scheme/amr_rule/transduction/atom_phenomena_extractor.py b/tenet/scheme/amr_clara_rule/transduction/atom_phenomena_extractor.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/atom_phenomena_extractor.py rename to tenet/scheme/amr_clara_rule/transduction/atom_phenomena_extractor.py diff --git a/tenet/scheme/amr_rule/transduction/atom_property_extractor.py b/tenet/scheme/amr_clara_rule/transduction/atom_property_extractor.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/atom_property_extractor.py rename to tenet/scheme/amr_clara_rule/transduction/atom_property_extractor.py diff --git a/tenet/scheme/amr_rule/transduction/atom_relation_propagator.py b/tenet/scheme/amr_clara_rule/transduction/atom_relation_propagator.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/atom_relation_propagator.py rename to tenet/scheme/amr_clara_rule/transduction/atom_relation_propagator.py diff --git a/tenet/scheme/amr_rule/transduction/atom_value_extractor.py b/tenet/scheme/amr_clara_rule/transduction/atom_value_extractor.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/atom_value_extractor.py rename to tenet/scheme/amr_clara_rule/transduction/atom_value_extractor.py diff --git a/tenet/scheme/amr_rule/transduction/composite_class_extractor_1.py b/tenet/scheme/amr_clara_rule/transduction/composite_class_extractor_1.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/composite_class_extractor_1.py rename to tenet/scheme/amr_clara_rule/transduction/composite_class_extractor_1.py diff --git a/tenet/scheme/amr_rule/transduction/composite_class_extractor_2.py b/tenet/scheme/amr_clara_rule/transduction/composite_class_extractor_2.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/composite_class_extractor_2.py rename to tenet/scheme/amr_clara_rule/transduction/composite_class_extractor_2.py diff --git a/tenet/scheme/amr_rule/transduction/phenomena_mod_analyzer_1.py b/tenet/scheme/amr_clara_rule/transduction/phenomena_mod_analyzer_1.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/phenomena_mod_analyzer_1.py rename to tenet/scheme/amr_clara_rule/transduction/phenomena_mod_analyzer_1.py diff --git a/tenet/scheme/amr_rule/transduction/phenomena_or_analyzer_1.py b/tenet/scheme/amr_clara_rule/transduction/phenomena_or_analyzer_1.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/phenomena_or_analyzer_1.py rename to tenet/scheme/amr_clara_rule/transduction/phenomena_or_analyzer_1.py diff --git a/tenet/scheme/amr_rule/transduction/phenomena_or_analyzer_2.py b/tenet/scheme/amr_clara_rule/transduction/phenomena_or_analyzer_2.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/phenomena_or_analyzer_2.py rename to tenet/scheme/amr_clara_rule/transduction/phenomena_or_analyzer_2.py diff --git a/tenet/scheme/amr_rule/transduction/phenomena_polarity_analyzer_1.py b/tenet/scheme/amr_clara_rule/transduction/phenomena_polarity_analyzer_1.py similarity index 100% rename from tenet/scheme/amr_rule/transduction/phenomena_polarity_analyzer_1.py rename to tenet/scheme/amr_clara_rule/transduction/phenomena_polarity_analyzer_1.py diff --git a/tenet/scheme/amr_master_rule/__init__.py b/tenet/scheme/amr_master_rule/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..778b294244be787ff09f90fe726d559a5a57726d --- /dev/null +++ b/tenet/scheme/amr_master_rule/__init__.py @@ -0,0 +1,21 @@ +from scheme.amr_master_rule.preprocessing.amr_reification import * +from scheme.amr_master_rule.preprocessing.amrld_correcting import * + +from scheme.amr_master_rule.transduction.atom_class_extractor import * +from scheme.amr_master_rule.transduction.atom_individual_extractor import * +from scheme.amr_master_rule.transduction.atom_property_extractor import * +from scheme.amr_master_rule.transduction.atom_value_extractor import * +from scheme.amr_master_rule.transduction.atom_phenomena_extractor import * +from scheme.amr_master_rule.transduction.atom_relation_propagator import * + +from scheme.amr_master_rule.transduction.composite_class_extractor_1 import * +from scheme.amr_master_rule.transduction.composite_class_extractor_2 import * + +from scheme.amr_master_rule.transduction.phenomena_polarity_analyzer_1 import * +from scheme.amr_master_rule.transduction.phenomena_mod_analyzer_1 import * +from scheme.amr_master_rule.transduction.phenomena_or_analyzer_1 import * +from scheme.amr_master_rule.transduction.phenomena_or_analyzer_2 import * + +from scheme.amr_master_rule.generation.owl_property_generator import * + +from scheme.amr_master_rule import * diff --git a/tenet/scheme/amr_master_rule/__rule_pattern.py b/tenet/scheme/amr_master_rule/__rule_pattern.py new file mode 100644 index 0000000000000000000000000000000000000000..c4a3a8829f6c5fd11df8993ed02238b7965cb3c4 --- /dev/null +++ b/tenet/scheme/amr_master_rule/__rule_pattern.py @@ -0,0 +1,169 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to xxx (rule i) [TODO] +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to xxx +# Rule: property(arg0:class, arg1:class) => compositeClass [TODO] +#============================================================================== + +from rdflib import Graph + +import transduction as transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Select Pattern: property(arg0:class, arg1:class) +#============================================================================== + +def __rule_pattern_query_code(graph): # TODO + select_data_list = ['?property_net', '?class_net_0', '?class_net_1'] + clause_list = [] + clause_list.append(f'?property_net a [rdfs:subClassOf* net:Property_Net].') + clause_list.append(f'FILTER NOT EXISTS {{ ?property_net a net:Deprecated_Net. }}') + clause_list.append(f'?class_net_0 a [rdfs:subClassOf* net:Class_Net].') + clause_list.append(f'FILTER NOT EXISTS {{ ?class_net_0 a net:Deprecated_Net. }}') + clause_list.append(f'?class_net_1 a [rdfs:subClassOf* net:Class_Net].') + clause_list.append(f'FILTER NOT EXISTS {{ ?class_net_1 a net:Deprecated_Net. }}') + clause_list.append(f'?property_net amr:role_ARG0 ?class_net_0.') + clause_list.append(f'?property_net amr:role_ARG1 ?class_net_1.') + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_pattern(graph): + query_code = __rule_pattern_query_code(graph) + rule_pattern_set = graph.query(query_code) + return rule_pattern_set + + + +#============================================================================== +# Net Checking +#============================================================================== + +def __verify_disjoint_cover(class_net_0, class_net_1): + check = True + for node in class_net_0.node: + if node in class_net_1.node: check = False + return check + + + +#============================================================================== +# Relation Propagation +#============================================================================== + +def __filter_relation(relation_list): + result_list = [] + for relation in relation_list: + check = True + (s, p, o) = relation + if s == o: check = False + if check: result_list.append(relation) + return result_list + + +def __propagate_relation(target_net, base_net): + # -- target_net.input_relation_list = base_net.input_relation_list + out_relation_list = __filter_relation(base_net.output_relation_list) + target_net.output_relation_list = out_relation_list + + + +#============================================================================== +# Construct Methods: construction of composite class net +#============================================================================== + +def __construct_restriction_net(graph, property_net_1, property_net_2): + + restriction_net = net.RestrictionNet(graph) + restriction_net.compose(property_net_1, property_net_2) + + # -- Data Computation + restriction_net.restriction_property = property_net_1.uri + restriction_net.restriction_net_value = property_net_2.uri + + # -- Relation Propagation: None + + # -- Net Naming + restriction_net.naming = define_restriction_naming(property_net_1, property_net_2) + + # -- Finalization + restriction_net.finalize() + triple_list = restriction_net.generate_triple_definition() + + return restriction_net, triple_list + + + +def __construct_composite_class_net_from_3_nets( + graph, base_class_net, core_property_net, target_class_net): + + # -- Net Composition + composite_class_net = net.CompositePropertyNet(graph) + composite_class_net.compose(base_class_net, core_property_net, target_class_net) + + # -- Data Computation + composite_class_net.mother_class_net = base_class_net.uri + + # -- Restriction Computation + restriction_net, triple_list_1 = __construct_restriction_net(graph, core_property_net, target_class_net) + composite_class_net.restriction = restriction_net.uri + + # -- Relation Propagation + __propagate_relation(composite_class_net, base_class_net) + + # -- Net Naming + composite_class_net.naming = define_composite_naming_1( + base_class_net, core_property_net, target_class_net) + + # -- Finalization + composite_class_net.finalize() + triple_list_2 = composite_class_net.generate_triple_definition() + result_triple_list = triple_list_1 + triple_list_2 + + return composite_class_net, result_triple_list + + + +#============================================================================== +# Main Method +#============================================================================== + +def extract_xxx(graph): # TODO + + # -- Rule Initialization + rule_label = 'extract xxx [ property(arg0:class, arg1:class) ]' + + # -- Search for patterns + rule_pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for selection_1 in rule_pattern_set: + + # -- Net Selection + property_net = net.PropertyNet(graph, uri=selection_1.property_net) + class_net_0 = net.ClassNet(graph, uri=selection_1.class_net_0) + class_net_1 = net.ClassNet(graph, uri=selection_1.class_net_1) + + # -- Condition: disjoint cover + if __verify_disjoint_cover(class_net_0, class_net_1): + + # -- New Net Construction (from 3 nets) + new_class, triple_list = __construct_composite_class_net_from_3_nets( + graph, class_net_0, property_net, class_net_1) + + # -- Resulting List Update + # class_net_list.append(new_class) + rule_triple_list += triple_list + + # -- Deprecation: Origin Class Net + rule_triple_list += class_net_0.deprecate() + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/generation/__init__.py b/tenet/scheme/amr_master_rule/generation/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..8d1c8b69c3fce7bea45c73efd06983e3c419a92f --- /dev/null +++ b/tenet/scheme/amr_master_rule/generation/__init__.py @@ -0,0 +1 @@ + diff --git a/tenet/scheme/amr_master_rule/generation/owl_property_generator.py b/tenet/scheme/amr_master_rule/generation/owl_property_generator.py new file mode 100644 index 0000000000000000000000000000000000000000..38e2380c33132d558e046d73c8ddd991fa4a2250 --- /dev/null +++ b/tenet/scheme/amr_master_rule/generation/owl_property_generator.py @@ -0,0 +1,192 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to conjunctive phenomena or (rule 1) +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to analyse conjunctive phenomena (or) +# Rule: property(class, or_phenomena) => compositeClass +#============================================================================== + +import rdflib +from rdflib import Graph +from rdflib.namespace import FOAF, RDF + +import transduction +from transduction import net +from transduction.rdfterm_computer import produce_uriref, produce_literal +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_axiom_naming +from transduction.naming_computer import define_composite_naming_2 + + +#============================================================================== +# Select Pattern: Atom / Composite Property Net +#============================================================================== + +def __search_pattern_1(graph): + select_data_list = ['?property_net'] + clause_list = [(f'?property_net a net:Atom_Property_Net.')] + query_code = generate_select_query(graph, select_data_list, clause_list) + rule_pattern_set = graph.query(query_code) + return rule_pattern_set + + +def __search_pattern_2(graph): + select_data_list = ['?property_net'] + clause_list = [(f'?property_net a net:Composite_Property_Net.')] + query_code = generate_select_query(graph, select_data_list, clause_list) + rule_pattern_set = graph.query(query_code) + return rule_pattern_set + + +def __get_atom_property_net_list(graph): + + # -- Atom Property List + atom_property_net_list = [] + atom_property_set = __search_pattern_1(graph) + for selection in atom_property_set: + property_net = net.AtomPropertyNet(graph, uri=selection.property_net) + atom_property_net_list.append(property_net) + + return atom_property_net_list + + +def __get_composite_property_net_list(graph): + + # -- Composite Property List + composite_property_net_list = [] + composite_property_set = __search_pattern_2(graph) + for selection in composite_property_set: + property_net = net.CompositePropertyNet(graph, uri=selection.property_net) + composite_property_net_list.append(property_net) + + return composite_property_net_list + + +def __get_mother_property_net_list(atom_property_net_list, composite_property_net_list): + + # -- URI List + mother_property_uri_list = [] + for net in composite_property_net_list: + if net.mother_property_net is not None: + mother_property_uri_list += net.mother_property_net + + # -- Net List + mother_property_net_list = [] + for net in (atom_property_net_list + composite_property_net_list): + if net.uri in mother_property_uri_list: + mother_property_net_list.append(net) + + return mother_property_net_list + + + +#============================================================================== +# Check Methods +#============================================================================== + +def __is_property_to_generate(property_net): + check_1 = property_net.is_deprecated() + if is_instance(property_net.mother_property_net, list): + check_2 = len(property_net.mother_property_net) > 0 + else: + check_2 = False + return not check_1 or check_2 + + + +#============================================================================== +# Generator Methods +#============================================================================== + +def __compute_property_uri(property_net): + if isinstance(property_net.property_uri, list) and len(property_net.property_uri) > 0: + property_uri = property_net.property_uri[0] + else: # computation of property_uri + net_naming = property_net.get_attribute_first_value(property_net.naming) + property_uri = produce_uriref(property_net.support_graph, f'ext-out:{net_naming}') + return property_uri + + +def __get_mother_property_uri(graph, mother_property_net_uri): + mother_property_net = net.PropertyNet(graph, uri=mother_property_net_uri) + return __compute_property_uri(mother_property_net) + + +def __define_triple(new_property_uri, relation, data): + triple_list = [] + for predicat in data: + triple_list.append((new_property_uri, relation, predicat)) + return triple_list + + +def __generate_owl_taxonomic_relation(graph, new_property_uri, net): + + triple_list = [] + relation = produce_uriref(graph, 'rdfs:subPropertyOf') + predicat = None + + if net.type_id == 'Atom_Property_Net': + predicat = produce_uriref(graph, 'base-out:Out_ObjectProperty') + + if net.type_id == 'Composite_Property_Net': + mother_property_net_uri = net.get_attribute_first_value(net.mother_property_net) + if mother_property_net_uri is None: + predicat = produce_uriref(graph, 'base-out:Out_ObjectProperty') + else : + predicat = __get_mother_property_uri(graph, mother_property_net_uri) + + if predicat is not None: + triple_list.append((new_property_uri, relation, predicat)) + + return triple_list + + +def __generate_owl_triple_definition(graph, net): + + triple_list = [] + + new_property_uri = __compute_property_uri(net) + + rdf_type_uri = produce_uriref(graph, RDF.type) + triple_list += __define_triple(new_property_uri, rdf_type_uri, net.property_type) + + relation = produce_uriref(graph, 'rdfs:label') + triple_list += __define_triple(new_property_uri, relation, net.property_name) + + relation = produce_uriref(graph, 'base-out:fromStructure') + triple_list += __define_triple(new_property_uri, relation, net.structure) + + triple_list += __generate_owl_taxonomic_relation(graph, new_property_uri, net) + + return triple_list + + + +#============================================================================== +# Main Method: analyze_phenomena_or_1 +#============================================================================== + +def generate_owl_property(graph): + + # -- Rule Initialization + rule_label = 'generate OWL property' + rule_triple_list = [] + + # -- Get property net listings + atom_property_net_list = __get_atom_property_net_list(graph) + composite_property_net_list = __get_composite_property_net_list(graph) + mother_property_net_list = __get_mother_property_net_list(atom_property_net_list, + composite_property_net_list) + + # -- Triple Definition for 'not deprecated property net' + for property_net in (atom_property_net_list + composite_property_net_list): + if not property_net.is_deprecated(): + rule_triple_list += __generate_owl_triple_definition(graph, property_net) + + # -- Triple Definition for 'mother property net' + for property_net in mother_property_net_list: + rule_triple_list += __generate_owl_triple_definition(graph, property_net) + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/nov_generation.py b/tenet/scheme/amr_master_rule/nov_generation.py new file mode 100644 index 0000000000000000000000000000000000000000..5b206fd43c11e96be8fba912b9ebc9cf8f0d5264 --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_generation.py @@ -0,0 +1,645 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'OWL Generation' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'OWL Generation' level +#============================================================================== + + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# OWL Generation: Preparation +# --------------------------------------------- + +rule_set['compute-uri-for-owl-declaration-1'] = { + 'label': "compute-uri-for-owl-declaration-1", + 'comment': ("Compute URI for OWL declaration: ", + " URI of classes "), + 'construction': """ + ?net1 net:hasClassURI ?newClassUri. + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassName ?className. + FILTER NOT EXISTS { ?net1 net:deprecated true. } + FILTER NOT EXISTS { ?net1 a net:Deprecated_Net. } + """, + 'binding': """ + BIND (CONCAT(str(ext-out:), str(?className)) AS ?c1). + BIND (uri(?c1) AS ?newClassUri). + """ +} + +rule_set['compute-uri-for-owl-declaration-2'] = { + 'label': "compute-uri-for-owl-declaration-2", + 'comment': ("Compute URI for OWL declaration: ", + " URI of mother classes "), + 'construction': """ + ?motherClassNet net:hasClassURI ?newClassUri. + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Class_Net] ; + net:hasMotherClassNet ?motherClassNet. + ?motherClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassName ?motherClassName. + """, + 'binding': """ + BIND (CONCAT(str(ext-out:), str(?motherClassName)) AS ?c1). + BIND (uri(?c1) AS ?newClassUri). + """ +} + +rule_set['compute-uri-for-owl-declaration-3'] = { + 'label': "compute-uri-for-owl-declaration-3", + 'comment': ("Compute URI for OWL declaration: ", + " URI of individuals "), + 'construction': """ + ?net1 net:hasIndividualURI ?newIndividualUri. + """, + 'clause': """ + ?net1 a net:Individual_Net ; + net:hasIndividualLabel ?individualLabel. + FILTER NOT EXISTS { ?net1 net:deprecated true. } + FILTER NOT EXISTS { ?net1 a net:Deprecated_Net. } + """, + 'binding': """ + BIND (REPLACE(?individualLabel, ' ', "-") AS ?iName1). + BIND (LCASE(str(?iName1)) AS ?iName2). + BIND (CONCAT(str(ext-out:), str(?iName2)) AS ?iName3). + BIND (uri(?iName3) AS ?newIndividualUri). + """ +} + +rule_set['compute-uri-for-owl-declaration-4'] = { + 'label': "compute-uri-for-owl-declaration-4", + 'comment': ("Compute URI for OWL declaration: ", + " mother class URI of individuals ", + " (case with a base ontology class) "), + 'construction': """ + ?net1 net:hasMotherClassURI ?newMotherClassUri. + """, + 'clause': """ + ?net1 a net:Individual_Net ; + net:hasBaseClassName ?motherClassName. + FILTER NOT EXISTS { ?net1 net:deprecated true. } + FILTER NOT EXISTS { ?net1 a net:Deprecated_Net. } + """, + 'binding': """ + BIND (CONCAT(str(base-out:), str(?motherClassName)) AS ?c1). + BIND (uri(?c1) AS ?newMotherClassUri). + """ +} + +rule_set['compute-uri-for-owl-declaration-5'] = { + 'label': "compute-uri-for-owl-declaration-5", + 'comment': ("Compute URI for OWL declaration: ", + " URI of properties "), + 'construction': """ + ?net1 net:hasPropertyURI ?newPropertyUri. + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Property_Net] ; + net:hasPropertyName ?propertyName. + FILTER NOT EXISTS { ?net1 net:deprecated true. } + FILTER NOT EXISTS { ?net1 a net:Deprecated_Net. } + """, + 'binding': """ + BIND (CONCAT(str(ext-out:), str(?propertyName)) AS ?c1). + BIND (uri(?c1) AS ?newPropertyUri). + """ +} + +rule_set['compute-uri-for-owl-declaration-6'] = { + 'label': "compute-uri-for-owl-declaration-6", + 'comment': ("Compute URI for OWL declaration: ", + " URI of properties (variant 12) "), + 'construction': """ + ?net1 net:hasProperty12URI ?newPropertyUri. + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Property_Net] ; + net:hasPropertyName12 ?propertyName12. + FILTER NOT EXISTS { ?net1 net:deprecated true. } + FILTER NOT EXISTS { ?net1 a net:Deprecated_Net. } + """, + 'binding': """ + BIND (CONCAT(str(ext-out:), str(?propertyName12)) AS ?c1). + BIND (uri(?c1) AS ?newPropertyUri). + """ +} + +rule_set['compute-uri-for-owl-declaration-7'] = { + 'label': "compute-uri-for-owl-declaration-7", + 'comment': ("Compute URI for OWL declaration: ", + " URI of mother properties "), + 'construction': """ + ?motherPropertyNet net:hasPropertyURI ?newPropertyUri. + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Property_Net] ; + net:hasMotherPropertyNet ?motherPropertyNet. + ?motherPropertyNet a [rdfs:subClassOf* net:Property_Net] ; + net:hasPropertyName ?motherPropertyName. + """, + 'binding': """ + BIND (CONCAT(str(ext-out:), str(?motherPropertyName)) AS ?c1). + BIND (uri(?c1) AS ?newPropertyUri). + """ +} + +# *** New Net *** URI from Naming attribute + +# rule_set['compute-uri-for-owl-declaration-101'] = { +# 'label': "compute-uri-for-owl-declaration-101", +# 'comment': ("Compute URI for OWL declaration: ", +# " URI of properties (from Naming) "), +# 'construction': """ +# ?net1 net:hasPropertyURI ?newPropertyUri. +# """, +# 'clause': """ +# ?net1 a [rdfs:subClassOf* net:Property_Net] ; +# net:hasNaming ?propertyName. +# FILTER NOT EXISTS { ?net1 net:deprecated true. } +# FILTER NOT EXISTS { ?net1 a net:Deprecated_Net. } +# """, +# 'binding': """ +# BIND (CONCAT(str(ext-out:), str(?propertyName)) AS ?c1). +# BIND (uri(?c1) AS ?newPropertyUri). +# """ +# } + +# rule_set['compute-uri-for-owl-declaration-102'] = { +# 'label': "compute-uri-for-owl-declaration-102", +# 'comment': ("Compute URI for OWL declaration: ", +# " URI of mother properties (from Naming) "), +# 'construction': """ +# ?motherPropertyNet net:hasPropertyURI ?newPropertyUri. +# """, +# 'clause': """ +# ?net1 a [rdfs:subClassOf* net:Property_Net] ; +# net:hasMotherPropertyNet ?motherPropertyNet. +# ?motherPropertyNet a [rdfs:subClassOf* net:Property_Net] ; +# net:hasNaming ?motherPropertyName. +# """, +# 'binding': """ +# BIND (CONCAT(str(ext-out:), str(?motherPropertyName)) AS ?c1). +# BIND (uri(?c1) AS ?newPropertyUri). +# """ +# } + + + +# --------------------------------------------- +# OWL Generation: Atom Class +# --------------------------------------------- + +rule_set['generate-atom-class'] = { + 'label': "generate-atom-class", + 'comment': "Generate Atom Class in the target ontology", + 'construction': """ + ?newClassUri rdf:type owl:Class ; + rdfs:label ?className ; + base-out:fromStructure ?sentenceRef. + """, + 'clause': """ + ?net1 a net:Atom_Class_Net ; + net:hasClassName ?className ; + net:hasStructure ?sentenceRef ; + net:hasClassURI ?newClassUri. + """, + 'binding': """ + """ +} + +rule_set['classify-atom-class-1'] = { + 'label': "classify-atom-class-1", + 'comment': "Classify Atom Class in the target ontology", + 'construction': """ + ?newClassUri rdfs:subClassOf ?classType. + """, + 'clause': """ + ?net1 a net:Atom_Class_Net ; + net:hasClassType ?classType ; + net:hasClassURI ?newClassUri. + """, + 'binding': """ + """ +} + +rule_set['classify-atom-class-2'] = { + 'label': "classify-atom-class-2", + 'comment': "Classify Atom Class in the target ontology", + 'construction': """ + ?newClassUri rdfs:subClassOf base-out:Undetermined_Thing. + """, + 'clause': """ + ?net1 a net:Atom_Class_Net ; + net:hasClassURI ?newClassUri. + FILTER NOT EXISTS { ?net1 net:hasClassType ?classType. } + FILTER NOT EXISTS { ?newClassUri rdfs:subClassOf* base-out:Out_Structure. } + """, + 'binding': """ + """ +} + + + + +# --------------------------------------------- +# OWL Generation: Individual +# --------------------------------------------- + +rule_set['generate-individual'] = { + 'label': "generate-individual", + 'comment': "Generate Individual in the target ontology", + 'construction': """ + ?newIndividualUri a owl:individual ; + rdfs:label ?individualLabel ; + base-out:fromStructure ?sentenceRef. + """, + 'clause': """ + ?net1 a net:Individual_Net ; + net:hasIndividualLabel ?individualLabel ; + net:hasIndividualURI ?newIndividualUri. + OPTIONAL { ?net1 net:hasStructure ?sentenceRef. } + """, + 'binding': """ + """ +} + +rule_set['classify-individual-1'] = { + 'label': "classify-individual-1", + 'comment': "Classify Individual in the target ontology", + 'construction': """ + ?newIndividualUri a ?motherClassURI. + """, + 'clause': """ + ?net1 a net:Individual_Net ; + net:hasMotherClassURI ?motherClassURI ; + net:hasIndividualURI ?newIndividualUri. + """, + 'binding': """ + """ +} + +rule_set['classify-individual-2'] = { + 'label': "classify-individual-2", + 'comment': "Classify Individual in the target ontology", + 'construction': """ + ?newIndividualUri a ?motherClassURI. + """, + 'clause': """ + ?net1 a net:Individual_Net ; + net:hasMotherClassNet ?motherClassNet ; + net:hasIndividualURI ?newIndividualUri. + ?motherClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?motherClassURI. + # -- old --- FILTER NOT EXISTS { ?motherClassNet net:deprecated true. } + """, + 'binding': """ + """ +} + + +# --------------------------------------------- +# OWL Generation: Atom Property +# --------------------------------------------- + +rule_set['generate-atom-property-1'] = { + 'label': "generate-atom-property-1", + 'comment': "Generate Atom Property in the target ontology", + 'construction': """ + ?newPropertyUri a ?propertyType ; + rdfs:subPropertyOf base-out:Out_ObjectProperty ; + rdfs:label ?propertyName ; + base-out:fromStructure ?sentenceRef. + """, + 'clause': """ + ?net1 a net:Atom_Property_Net ; + net:hasPropertyType ?propertyType ; + net:hasPropertyName ?propertyName ; + net:hasStructure ?sentenceRef ; + net:hasPropertyURI ?newPropertyUri. + """, + 'binding': """ + """ +} + +rule_set['generate-atom-property-12'] = { + 'label': "generate-atom-property-12", + 'comment': "Generate Atom Property (variant 12) in the target ontology", + 'construction': """ + ?newProperty12Uri a ?propertyType ; + rdfs:subPropertyOf base-out:Out_ObjectProperty ; + rdfs:label ?propertyName12 ; + base-out:fromStructure ?sentenceRef. + """, + 'clause': """ + ?net1 a net:Atom_Property_Net ; + net:hasPropertyType ?propertyType ; + net:hasPropertyName12 ?propertyName12 ; + net:hasStructure ?sentenceRef ; + net:hasProperty12URI ?newProperty12Uri. + """, + 'binding': """ + """ +} + +rule_set['generate-inverse-relation'] = { + 'label': "generate-inverse-relation", + 'comment': ("Generate OWL inverseOf relation between two properties", + " in the target ontology"), + 'construction': """ + ?prop1Uri owl:inverseOf ?prop2Uri. + """, + 'clause': """ + ?net1 net:inverseOf ?net2. + ?net1 net:hasPropertyURI ?prop1Uri. + ?net2 net:hasPropertyURI ?prop2Uri. + """, + 'binding': """ + """ +} + + + +# --------------------------------------------- +# OWL Generation: Composite Class (Taxonomy relation) +# --------------------------------------------- + +rule_set['generate-composite-class'] = { + 'label': "generate-composite-class", + 'comment': "Generate Composite Class in the target ontology", + 'construction': """ + ?newClassUri a owl:Class ; + rdfs:subClassOf ?motherClassUri ; + rdfs:label ?className ; + base-out:fromStructure ?sentenceRef. + """, + 'clause': """ + ?net1 a net:Composite_Class_Net ; + net:hasClassName ?className ; + net:hasStructure ?sentenceRef ; + net:hasClassURI ?newClassUri ; + net:hasMotherClassNet ?motherClassNet. + ?motherClassNet net:hasClassURI ?motherClassUri. + """, + 'binding': """ + """ +} + + + +# --------------------------------------------- +# OWL Generation: Class Restriction +# --------------------------------------------- + +rule_set['add-restriction-to-class-1'] = { + 'label': "add-restriction-to-class-1", + 'comment': ("Add restriction to Class: ", + " (1) on property, ", + " (2) with some values from a class ", + " (corresponding to a class net)", + " (3) for standard case"), + 'construction': """ + ?newClassUri a owl:Class ; + rdfs:subClassOf [ + a owl:Restriction ; + owl:onProperty ?onPropertyUri ; + owl:someValuesFrom ?valuesClassUri + ] . + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?newClassUri ; + net:hasRestriction ?restrictionNet. + ?restrictionNet a net:Restriction_Net; + net:hasRestrictionOnProperty ?onPropertyNet ; + net:hasRestrictionNetValue ?valueNet. + ?onPropertyNet net:hasPropertyURI ?onPropertyUri. + ?valueNet a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?valuesClassUri. + """, + 'binding': """ + """ +} + +rule_set['add-restriction-to-class-2'] = { + 'label': "add-restriction-to-class-2", + 'comment': ("Add restriction to Class: ", + " (1) on property, ", + " (2) with individual for value ", + " (corresponding to an individual net)", + " (3) for standard case"), + 'construction': """ + ?newClassUri a owl:Class ; + rdfs:subClassOf [ + a owl:Restriction ; + owl:onProperty ?onPropertyUri ; + owl:hasValue ?valueIndividualUri + ] . + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?newClassUri ; + net:hasRestriction ?restrictionNet. + ?restrictionNet a net:Restriction_Net; + net:hasRestrictionOnProperty ?onPropertyNet ; + net:hasRestrictionNetValue ?valueNet. + ?onPropertyNet net:hasPropertyURI ?onPropertyUri. + ?valueNet a net:Individual_Net ; + net:hasIndividualURI ?valueIndividualUri. + """, + 'binding': """ + """ +} + +rule_set['add-restriction-to-class-3'] = { + 'label': "add-restriction-to-class-3", + 'comment': ("Add restriction to Class: ", + " (1) on property, ", + " (2) with some values from a class ", + " (corresponding to a class net)", + " (3) for variant 01"), + 'construction': """ + ?newClassUri a owl:Class ; + rdfs:subClassOf [ + a owl:Restriction ; + owl:onProperty ?onPropertyUri ; + owl:someValuesFrom ?valuesClassUri + ] . + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?newClassUri ; + net:hasRestriction01 ?restrictionNet. + ?restrictionNet a net:Restriction_Net; + net:hasRestrictionOnProperty ?onPropertyNet ; + net:hasRestrictionNetValue ?valueNet. + ?onPropertyNet net:hasProperty12URI ?onPropertyUri. + ?valueNet a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?valuesClassUri. + """, + 'binding': """ + """ +} + +rule_set['add-restriction-to-class-4'] = { + 'label': "add-restriction-to-class-4", + 'comment': ("Add restriction to Class: ", + " (1) on property, ", + " (2) with individual for value ", + " (corresponding to an individual net)", + " (3) for variant 01"), + 'construction': """ + ?newClassUri a owl:Class ; + rdfs:subClassOf [ + a owl:Restriction ; + owl:onProperty ?onPropertyUri ; + owl:hasValue ?valueIndividualUri + ] . + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?newClassUri ; + net:hasRestriction01 ?restrictionNet. + ?restrictionNet a net:Restriction_Net; + net:hasRestrictionOnProperty ?onPropertyNet ; + net:hasRestrictionNetValue ?valueNet. + ?onPropertyNet net:hasProperty12URI ?onPropertyUri. + ?valueNet a net:Individual_Net ; + net:hasIndividualURI ?valueIndividualUri. + """, + 'binding': """ + """ +} + +rule_set['add-restriction-to-class-5'] = { + 'label': "add-restriction-to-class-5", + 'comment': ("Add restriction to Class: ", + " (1) on property, ", + " (2) with some values from a class ", + " (corresponding to a class net)", + " (3) for variant 12"), + 'construction': """ + ?newClassUri a owl:Class ; + rdfs:subClassOf [ + a owl:Restriction ; + owl:onProperty ?onPropertyUri ; + owl:someValuesFrom ?valuesClassUri + ] . + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?newClassUri ; + net:hasRestriction12 ?restrictionNet. + ?restrictionNet a net:Restriction_Net; + net:hasRestrictionOnProperty ?onPropertyNet ; + net:hasRestrictionNetValue ?valueNet. + ?onPropertyNet net:hasProperty12URI ?onPropertyUri. + ?valueNet a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?valuesClassUri. + """, + 'binding': """ + """ +} + +rule_set['add-restriction-to-class-6'] = { + 'label': "add-restriction-to-class-6", + 'comment': ("Add restriction to Class: ", + " (1) on property, ", + " (2) with individual for value ", + " (corresponding to an individual net)", + " (3) for variant 12"), + 'construction': """ + ?newClassUri a owl:Class ; + rdfs:subClassOf [ + a owl:Restriction ; + owl:onProperty ?onPropertyUri ; + owl:hasValue ?valueIndividualUri + ] . + """, + 'clause': """ + ?net1 a [rdfs:subClassOf* net:Class_Net] ; + net:hasClassURI ?newClassUri ; + net:hasRestriction12 ?restrictionNet. + ?restrictionNet a net:Restriction_Net; + net:hasRestrictionOnProperty ?onPropertyNet ; + net:hasRestrictionNetValue ?valueNet. + ?onPropertyNet net:hasProperty12URI ?onPropertyUri. + ?valueNet a net:Individual_Net ; + net:hasIndividualURI ?valueIndividualUri. + """, + 'binding': """ + """ +} + + + +# --------------------------------------------- +# OWL Generation: Composite Property +# --------------------------------------------- + +# rule_set['generate-composite-property-1'] = { +# 'label': "generate-composite-property-1", +# 'comment': "Generate Composite Property in the target ontology", +# 'construction': """ +# ?newPropertyUri a ?propertyType ; +# rdfs:label ?propertyName ; +# base-out:fromStructure ?sentenceRef. +# """, +# 'clause': """ +# ?net1 a net:Composite_Property_Net ; +# net:hasPropertyType ?propertyType ; +# net:hasPropertyName ?propertyName ; +# net:hasStructure ?sentenceRef ; +# net:hasPropertyURI ?newPropertyUri. +# """, +# 'binding': """ +# """ +# } + +# rule_set['generate-composite-property-2'] = { +# 'label': "generate-composite-property-2", +# 'comment': "Generate Composite Property in the target ontology", +# 'construction': """ +# ?newPropertyUri a ?propertyType ; +# rdfs:subPropertyOf base-out:Out_ObjectProperty ; +# rdfs:label ?propertyName ; +# base-out:fromStructure ?sentenceRef. +# """, +# 'clause': """ +# ?net1 a net:Composite_Property_Net ; +# net:hasPropertyType ?propertyType ; +# net:hasNaming ?propertyName ; +# net:hasStructure ?sentenceRef ; +# net:hasPropertyURI ?newPropertyUri. +# """, +# 'binding': """ +# """ +# } + +# rule_set['generate-composite-property-3'] = { +# 'label': "generate-composite-property-3", +# 'comment': "Generate Composite Property in the target ontology", +# 'construction': """ +# ?newPropertyUri rdfs:subPropertyOf ?motherPropertyUri. +# """, +# 'clause': """ +# ?net1 a net:Composite_Property_Net ; +# net:hasPropertyURI ?newPropertyUri ; +# net:hasMotherPropertyNet ?motherPropertyNet. +# ?motherPropertyNet net:hasPropertyURI ?motherPropertyUri. +# """, +# 'binding': """ +# """ +# } diff --git a/tenet/scheme/amr_master_rule/nov_transduction/__init__.py b/tenet/scheme/amr_master_rule/nov_transduction/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..8d1c8b69c3fce7bea45c73efd06983e3c419a92f --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/__init__.py @@ -0,0 +1 @@ + diff --git a/tenet/scheme/amr_master_rule/nov_transduction/atomic_extraction.py b/tenet/scheme/amr_master_rule/nov_transduction/atomic_extraction.py new file mode 100644 index 0000000000000000000000000000000000000000..867b4598357138bb65b45a7cafa78aac8c044366 --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/atomic_extraction.py @@ -0,0 +1,371 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# Query Builder Imports +#============================================================================== + +#import query_builder.construct as construct +from query_builder.builders import * + + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Atomic Extraction: Class Net +# --------------------------------------------- + +rule_set['create-atom-class-net'] = { + 'label': "create-atom-class-net", + 'comment': "Create Atom Class Net from AMR Term Concept", + 'construction': f""" + {atom_class_net.construct(base_node='?leaf1', + class_name='?conceptName', + naming='?conceptName')} + + {atom_class_net.propagate_relations()} + """, + 'clause': f""" + # -- Identify Class covering a single leaf + ?leaf1 a amr:AMR_Leaf ; + amr:hasConcept ?leaf1Concept ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + ?leaf1Concept rdfs:subClassOf amr:AMR_Term_Concept. + ?leaf1Concept amr:label ?conceptName. + + {atom_class_net.complete_clauses_for_construction('?leaf1')} + """, + 'binding': f""" + {atom_class_net.bind_uri('?conceptName', '?varLabel')} + """ +} + + +# --------------------------------------------- +# Atomic Extraction: Individual Net +# --------------------------------------------- + +rule_set['create-individual-net-1'] = { + 'label': "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': f""" + {individual_net.construct(base_node='?baseLeaf', + naming='?conceptName', + mother_class_net='?classNet', + individual_label='?valueLabel')} + + {individual_net.propagate_relations()} + """, + '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'}} + ?value a amr:AMR_Value ; + rdfs:label ?valueLabel. + ?classNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?baseLeaf ; + net:hasClassName ?conceptName. + + {individual_net.complete_clauses_for_construction('?baseLeaf')} + """, + 'binding': f""" + {individual_net.bind_uri('?conceptName', '?valueLabel')} + """ +} + + +# --------------------------------------------- +# Atomic Extraction: Property Net +# --------------------------------------------- + +rule_set['create-atom-property-net-1'] = { + 'label': "create-atom-property-net-1", + 'comment': ("Create Atom Property Net: ", + " (1) from AMR Predicat Concept"), + 'construction': f""" + {atom_property_net.construct(base_node='?baseLeaf', + naming='?propertyName', + 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': f""" + # -- Identify property covering single leaf + ?baseLeaf a amr:AMR_Leaf ; + amr:hasConcept ?concept ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + ?concept rdfs:subClassOf amr:AMR_Predicat_Concept ; + amr:label ?predicateLabel. + OPTIONAL {{ + ?baseLeaf ?relation ?argLeaf. + ?relation amr:hasAmrRole ?someArgRole. + }} + + {atom_property_net.complete_clauses_for_construction('?baseLeaf')} + """, + 'binding': f""" + BIND (STRBEFORE(?predicateLabel, '-') AS ?pName1). + BIND (IF (STRLEN(?pName1) > 0, + ?pName1, ?predicateLabel) AS ?propertyName) + BIND (IF (STRLEN(?pName1) > 0, + CONCAT(?propertyName, 'ing'), ?predicateLabel) AS ?propertyName01) + BIND (IF (STRLEN(?pName1) > 0, + CONCAT(?propertyName, '-by'), ?predicateLabel) AS ?propertyName10) + BIND (IF (STRLEN(?pName1) > 0, + CONCAT(?propertyName, '-of'), ?predicateLabel) AS ?propertyName12) + + {atom_property_net.bind_uri('?propertyName', '?varLabel')} + """ +} + +# -- old --- +# rule_set['create-atom-property-net-2'] = { +# 'label': "create-atom-property-net-2", +# 'comment': ("Create Property Net from AMR Predicat Concept: ", +# " with variable corresponding to a negative polarity value "), +# 'construction': f""" +# # -- 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. +# """, +# 'clause': """ +# # -- Identify property covering single leaf +# ?baseLeaf a amr:AMR_Leaf ; +# amr:hasConcept ?concept ; +# amr:hasVariable ?variable. +# ?variable amr:label ?varLabel ; +# amr:polarity ?polarityValue. +# ?polarityValue rdfs:label 'negative'. +# ?concept rdfs:subClassOf amr:AMR_Predicat_Concept ; +# amr:label ?predicateLabel. +# 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.} +# """, +# 'binding': f""" +# # -- New Property Name +# BIND (STRBEFORE(?predicateLabel, '-') AS ?basePropertyName). +# BIND (CONCAT('not-', ?basePropertyName) AS ?propertyName). +# BIND (CONCAT(?propertyName, 'ing') AS ?propertyName01). +# BIND (CONCAT(?propertyName, '-by') AS ?propertyName10). +# 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). +# """ +# } +# -- --- + +# -- old --- +# rule_set['create-atom-property-net-3'] = { +# 'label': "create-atom-property-net-3", +# 'comment': ("Create Atom Property Net: ", +# " (1) from AMR Non Core Role Edge"), +# 'construction': f""" +# # -- New Property Net +# ?newNet a net:Atom_Property_Net ; +# net:isCoreRoleLinked false ; +# net:hasStructure ?sentenceRef ; +# net:coverBaseNode ?baseLeaf ; +# net:targetArgumentNode ?targetPropertyLeaf ; +# net:hasPropertyType ?roleType ; +# net:hasPropertyRole ?relationRole ; +# net:hasPropertyName ?roleName. + +# # -- Propagation of relations (from nodes to nets) +# ?inRelationRole a net:Relation. +# ?inNet ?inRelationRole ?newNet. +# ?outRelationRole a net:Relation. +# ?newNet ?outRelationRole ?outNet. +# """, +# 'clause': """ +# # -- Identify property covering relation role +# ?relationRole rdfs:subClassOf amr:AMR_NonCore_Role ; +# amr:getPropertyType ?roleType ; +# amr:getDirectPropertyName ?roleName. +# FILTER (?roleType = owl:ObjectProperty || +# ?roleType = owl:DataProperty). +# ?roleEdge amr:hasAmrRole ?relationRole. +# ?baseLeaf ?roleEdge ?targetPropertyLeaf. +# ?baseLeaf a amr:AMR_Leaf ; +# amr:hasVariable ?variable. +# ?variable amr:label ?varLabel. + +# # -- 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': f""" +# # -- New Property Net +# BIND (CONCAT(str(net:), 'atomProperty') AS ?n1). +# BIND (CONCAT(?n1, '_', str(?roleName)) AS ?n2). +# BIND (CONCAT(?n2, '_', str(?varLabel)) AS ?n3). +# BIND (uri(?n3) AS ?newNet). +# """ +# } +# -- --- + + +# --------------------------------------------- +# Atomic Extraction: Value Net +# --------------------------------------------- + +rule_set['create-value-net'] = { + 'label': "create-value-net", + 'comment': "Create Value Net from AMR Value", + 'construction': f""" + {value_net.construct(naming='?valueLabel', + value_label='?valueLabel')} + + {value_net.propagate_relations()} + """, + 'clause': f""" + # -- Identify Class covering a single leaf + ?value a amr:AMR_Value ; + rdfs:label ?valueLabel. + + {value_net.complete_clauses_for_construction('?value')} + """, + 'binding': f""" + {value_net.bind_uri('?valueLabel')} + """ +} + +# --------------------------------------------- +# Atomic Extraction: Phenomena Net +# --------------------------------------------- + +rule_set['create-phenomena-net-1'] = { + 'label': "create-phenomena-net-1", + 'comment': ("Create Phenomena Net from AMR Relation Concept"), + 'construction': f""" + {phenomena_net.construct(base_node='?baseLeaf', + naming='?phenomenaLabel', + phenomena_type='?relationConceptPhenomena', + phenomena_ref='?relationConceptLabel')} + + {phenomena_net.propagate_relations()} + """, + 'clause': f""" + # Identify relation concept (phenomena) covering a single leaf + ?baseLeaf a amr:AMR_Leaf ; + amr:hasConcept ?concept ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + ?concept rdfs:subClassOf amr:AMR_Relation_Concept ; + amr:hasPhenomenaLink ?relationConceptPhenomena ; + amr:label ?relationConceptLabel. + ?relationConceptPhenomena amr:label ?phenomenaLabel. + ?baseLeaf ?relation ?argLeaf. + ?relation amr:hasAmrRole ?someArgRole. + + {phenomena_net.complete_clauses_for_construction('?baseLeaf')} + """, + 'binding': f""" + {phenomena_net.bind_uri('?phenomenaLabel', '?varLabel')} + """ +} + + +#============================================================================== +# Development Test +#============================================================================== + +if __name__ == '__main__': + + print('\n' + ' *** Development Test ***') + + print('\n' + ' -- test: Atom Class Net') + print(atom_class_net) + + print('\n' + ' -- test: update a test query (1)') + #rule = rule_set['create-atom-property-net-1'] + #rule = rule_set['create-value-net'] + rule = rule_set['create-individual-net-1'] + + test_query_1 = f"""[...] + CONSTRUCT {{ + {rule['construction']} + + + }} + WHERE {{ + {rule['clause']} + + {rule['binding']} + + }} + """ + print(test_query_1) + + print('\n' + ' *** - ***') diff --git a/tenet/scheme/amr_master_rule/nov_transduction/classification.py b/tenet/scheme/amr_master_rule/nov_transduction/classification.py new file mode 100644 index 0000000000000000000000000000000000000000..501764a4c3f0d888680f4e4de2bc16787ca79a88 --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/classification.py @@ -0,0 +1,364 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Net Expansion: Classification +# --------------------------------------------- + +rule_set['classify-net-from-core-1'] = { + 'label': "classify-net-from-core-1", + 'comment': ("Classify Class Net from relations corresponding to: ", + " Core property :ARG0 "), + 'construction': """ + ?rightClassNet net:hasClassType base-out:Entity. + """, + 'clause': """ + ?rightClassNet a [rdfs:subClassOf* net:Class_Net]. + ?leftNet amr:role_ARG0 ?rightClassNet. + """, + 'binding': """ + """ +} + +rule_set['classify-net-from-core-2'] = { + 'label': "classify-net-from-core-2", + 'comment': ("Classify Class Net from relations corresponding to: ", + " Core property :ARG1 "), + 'construction': """ + ?rightClassNet net:hasClassType base-out:Entity. + """, + 'clause': """ + ?rightClassNet a [rdfs:subClassOf* net:Class_Net]. + ?leftNet amr:role_ARG1 ?rightClassNet. + """, + 'binding': """ + """ +} + + +rule_set['classify-net-from-core-3'] = { + 'label': "classify-net-from-core-3", + 'comment': ("Classify Class Net from relations corresponding to: ", + " Core property :ARG2 "), + 'construction': """ + # -- 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. + + # -- Original net becomes deprecated + # -- old --- ?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': """ + ?rightClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:hasClassName ?rightConceptName. + OPTIONAL { ?restrictionNet net:hasRestrictionNetValue ?rightClassNet. } + ?leftNet amr:role_ARG2 ?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 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 net + BIND (CONCAT(str(net:), 'individual') AS ?n1). + BIND (CONCAT(?n1, '_', ?rightConceptName) AS ?n2). + BIND (CONCAT(?n2, '_', 'fromClass') AS ?n3). + BIND (uri(?n3) AS ?newNet). + """ +} + +# 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 ?newClassName. +# ?restrictionNet net:hasRestrictionNetValue ?newNet. + +# # -- Original net becomes deprecated +# # -- old --- ?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]; +# 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 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", + 'comment': ("Classify Class Net from relations corresponding to: ", + " Non-Core property :PART "), + 'construction': """ + ?leftClassNet net:hasClassType base-out:Entity. + ?rightClassNet net:hasClassType base-out:Entity. + """, + 'clause': """ + ?leftClassNet a [rdfs:subClassOf* net:Class_Net]. + ?rightClassNet a [rdfs:subClassOf* net:Class_Net]. + ?leftClassNet amr:role_part ?rightClassNet. + """, + 'binding': """ + """ +} + +rule_set['classify-net-from-domain'] = { + 'label': "classify-net-from-domain", + 'comment': ("Classify Class Net from relations corresponding to: ", + " Non-Core property :DOMAIN "), + 'construction': """ + ?leftClassNet net:hasMotherClassNet ?rightClassNet. + """, + 'clause': """ + ?leftClassNet a [rdfs:subClassOf* net:Class_Net]. + ?rightClassNet a [rdfs:subClassOf* net:Class_Net]. + ?leftClassNet amr:role_domain ?rightClassNet. + """, + 'binding': """ + """ +} + +rule_set['classify-net-from-degree-phenomena-1'] = { + 'label': "classify-net-from-degree-phenomena-1", + 'comment': ("Classify Class Net from relations corresponding to: ", + " (1) phenomena :DEGREE ", + " (2) core role :ARG1 or :ARG5"), + 'construction': """ + ?rightClassNet net:hasClassType base-out:Entity. + """, + 'clause': """ + ?phenomenaNet a net:Phenomena_Net ; + net:targetArgumentNode ?rightLeaf ; + net:hasPhenomenaType amr:phenomena_degree. + ?rightClassNet a [rdfs:subClassOf* net:Class_Net]. + ?phenomenaNet ?role ?rightClassNet. + FILTER (?role = amr:role_ARG1 || + ?role = amr:role_ARG5). + """, + 'binding': """ + """ +} + +rule_set['classify-net-from-degree-phenomena-2'] = { + 'label': "classify-net-from-degree-phenomena-2", + 'comment': ("Classify Class Net from relations corresponding to: ", + " (1) phenomena :DEGREE ", + " (2) core role :ARG2"), + 'construction': """ + ?newNet a net:Individual_Net ; + net:fromClassNet ?rightClassNet ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:hasBaseClassName 'Feature' ; + net:hasIndividualLabel ?rightConceptName. + ?restrictionNet net:hasRestrictionNetValue ?newNet. + + # -- Original net becomes deprecated + # -- old --- ?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': """ + ?phenomenaNet a net:Phenomena_Net ; + net:targetArgumentNode ?baseLeaf ; + net:hasPhenomenaType amr:phenomena_degree. + ?rightClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:hasStructure ?sentenceRef ; + net:hasClassName ?rightConceptName. + OPTIONAL { ?restrictionNet net:hasRestrictionNetValue ?rightClassNet. } + ?phenomenaNet amr:role_ARG2 ?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 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). + """ +} + +rule_set['classify-net-from-degree-phenomena-3'] = { + 'label': "classify-net-from-degree-phenomena-3", + 'comment': ("Classify Class Net from relations corresponding to: ", + " (1) phenomena :DEGREE ", + " (2) core role :ARG3"), + 'construction': """ + ?rightClassNet net:hasClassType base-out:Degree. + """, + 'clause': """ + ?phenomenaNet a net:Phenomena_Net ; + net:targetArgumentNode ?rightLeaf ; + net:hasPhenomenaType amr:phenomena_degree. + ?rightClassNet a [rdfs:subClassOf* net:Class_Net]. + ?phenomenaNet amr:role_ARG3 ?rightClassNet. + """, + 'binding': """ + """ +} + +rule_set['propagate-individual-1'] = { + 'label': "propagate-individual-1", + 'comment': ("Propagate Individual by completing Individual Net for: ", + " (1) same base node cover between several classes"), + 'construction': """ + ?individualNet net:hasMotherClassNet ?classNet. + """, + 'clause': """ + ?individualNet a net:Individual_Net ; + net:coverBaseNode ?sameBaseLeaf. + ?classNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?sameBaseLeaf. + """, + 'binding': """ + """ +} + +rule_set['propagate-individual-2'] = { + 'label': "propagate-individual-2", + 'comment': ("Propagate Individual by completing Individual Net for: ", + " (1) link between conjunction and domain phenomenas"), + 'construction': """ + ?individualNet net:hasMotherClassNet ?classNet. + """, + 'clause': """ + ?classNet a [rdfs:subClassOf* net:Class_Net]. + ?individualNet a net:Individual_Net. + ?classNet amr:role_domain ?individualNet. + """, + 'binding': """ + """ +} + +rule_set['reclassify-deprecated-net'] = { + 'label': "reclassify-deprecated-net", + 'comment': ("Reclassify deprecated net as Deprecated_Net instances"), + 'construction': """ + # -- Net becomes deprecated net + ?net a net:Deprecated_Net. + """, + 'clause': """ + # -- Identify net with deprecated mark + ?net a [rdfs:subClassOf* net:Net_Structure] ; + net:deprecated true. + """, + 'binding': """ + """ +} + +#============================================================================== +# Development Test +#============================================================================== + +if __name__ == '__main__': + + print('\n' + ' *** Development Test ***') + + print('\n' + ' -- Test Query') + rule = rule_set['propagate-individual-1'] + 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/tenet/scheme/amr_master_rule/nov_transduction/composite_class_extraction_1.py b/tenet/scheme/amr_master_rule/nov_transduction/composite_class_extraction_1.py new file mode 100644 index 0000000000000000000000000000000000000000..50afe9dec91a460f8b5ae4e62f59b96105dff531 --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/composite_class_extraction_1.py @@ -0,0 +1,457 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# Query Builder Imports +#============================================================================== + +#import query_builder.construct as construct +from query_builder.builders import * + + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Net Expansion: Composite Class Net from Property Net +# --------------------------------------------- + +rule_set['create-composite-class-net-from-property-1'] = { + 'label': "create-composite-class-net-from-property-1", + 'comment': ("Create Composite Class Net (and Restriction Net): ", + " (1) from relation between two classes as ARG0 and ARG1, ", + " (2) with a relation corresponding to Core Role property"), + 'construction': f""" + {restriction_net.construct(base_node=class_net_0.base_node, + naming='?newClassName', + target_node=atom_property_net.node, + restriction_property=atom_property_net.id, + restriction_net_value=class_net_1.id)} + {restriction_net.add_attribute(target_node=class_net_1.node)} + + {composite_class_net.construct(base_node=class_net_0.base_node, + node=atom_property_net.base_node, + class_name='?newClassName', + mother_class_net=class_net_0.id, + restriction01=restriction_net.id)} + {composite_class_net.add_attribute(node=class_net_0.node)} + {composite_class_net.add_attribute(node=class_net_1.node)} + """, + 'clause': f""" + # *** Identify Property(arg0:Class, arg1:Class) *** + + {atom_property_net.identify_net(core_role='true')} + + {atom_property_net.id} amr:role_ARG0 {class_net_0.id}. + {atom_property_net.id} amr:role_ARG1 {class_net_1.id}. + + {class_net_0.identify_net()} + + {class_net_1.identify_net()} + + # *** condition: disjoint cover *** + FILTER NOT EXISTS {{ + {class_net_0.id} net:coverNode ?node. + {class_net_1.id} net:coverNode ?node. + }} + + # *** Identify variable label of base leaf *** + {class_net_0.base_node} a amr:AMR_Leaf ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + """, + 'binding': f""" + # -- New Class Name + BIND (CONCAT({class_net_0.class_name}, '-', {atom_property_net.property_name01}) AS ?cn1). + BIND (CONCAT(?cn1, '-', {class_net_1.class_name}) AS ?newClassName). + + {restriction_net.bind_uri(atom_property_net.property_name01, class_net_1.class_name)} + + {composite_class_net.bind_uri('?newClassName', '?varLabel')} + """ +} + + +# -- old --- +# rule_set['create-composite-class-net-from-property-1'] = { +# 'label': "create-composite-class-net-from-property-1", +# 'comment': ("Create Composite Class Net (and Restriction Net): ", +# " (1) from relation between two classes as ARG0 and ARG1, ", +# " (2) with a relation corresponding to Core Role property", +# " (3) in normal direction"), +# 'construction': """ +# # -- New Restriction Net +# ?newRestrictionNet a net:Restriction_Net ; +# net:hasStructure ?sentenceRef ; +# net:coverBaseNode ?baseLeaf ; +# net:coverTargetNode ?propertyLeaf, +# ?nodeOfArg1Net ; +# net:hasRestrictionOnProperty ?propertyNet ; +# net:hasRestrictionNetValue ?arg1Net. + +# # -- New Class Net +# ?newNet a net:Composite_Class_Net ; +# net:hasStructure ?sentenceRef ; +# net:coverBaseNode ?baseLeaf ; +# net:coverNode ?propertyLeaf, +# ?nodeOfArg0Net, +# ?nodeOfArg1Net ; +# net:hasClassName ?newClassName ; +# net:hasMotherClassNet ?arg0Net ; +# net:hasRestriction01 ?newRestrictionNet. + +# # -- Propagation of relations (from nodes to nets) +# ?inRelationRole a net:Relation. +# ?inNet ?inRelationRole ?newNet. +# ?outRelationRole a net:Relation. +# ?newNet ?outRelationRole ?outNet. +# """, +# 'clause': """ +# # -- Identify Property(arg0:Class, arg1:Class) +# ?propertyNet a [rdfs:subClassOf* net:Property_Net] ; +# net:isCoreRoleLinked true ; +# net:hasStructure ?sentenceRef ; +# net:coverNode ?propertyLeaf ; +# net:hasPropertyName01 ?propertyName01. +# # -- old --- net:hasPropertyDirection net:normal_direction. +# ?propertyNet amr:role_ARG0 ?arg0Net. +# ?arg0Net a [rdfs:subClassOf* net:Class_Net] ; +# net:coverBaseNode ?baseLeaf ; +# net:coverNode ?nodeOfArg0Net ; +# net:hasClassName ?arg0Name. +# ?propertyNet amr:role_ARG1 ?arg1Net. +# ?arg1Net a [rdfs:subClassOf* net:Class_Net] ; +# net:coverBaseNode ?arg1Leaf ; +# net:coverNode ?nodeOfArg1Net ; +# net:hasClassName ?arg1Name. + +# # -- condition: disjoint cover +# FILTER NOT EXISTS {?arg0Net net:coverNode ?node. +# ?arg1Net net:coverNode ?node.} + +# # -- 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 Class Name +# BIND (CONCAT(?arg0Name, '-', ?propertyName01) AS ?cn1). +# BIND (CONCAT(?cn1, '-', ?arg1Name) AS ?newClassName). + +# # -- New Restriction Net +# BIND (CONCAT(str(net:), 'restriction') AS ?rn1). +# BIND (CONCAT(?rn1, '_', str(?propertyName01)) AS ?rn2). +# BIND (CONCAT(?rn2, '_', str(?arg1Name)) AS ?rn3). +# BIND (uri(?rn3) AS ?newRestrictionNet). + +# # -- New Class Net +# BIND (CONCAT(str(net:), 'compositeClass') AS ?n1). +# BIND (CONCAT(?n1, '_', ?newClassName) AS ?n2). +# BIND (uri(?n2) AS ?newNet). +# """ +# } +# -- --- + + + +rule_set['create-composite-class-net-from-property-2'] = { + 'label': "create-composite-class-net-from-property-2", + 'comment': ("Create Composite Class Net (and Restriction Net): ", + " (1) from relation between two classes as ARG1 and ARG2, ", + " (2) with a relation corresponding to Core Role property"), + 'construction': f""" + + {restriction_net.construct(base_node=class_net_1.base_node, + naming='?newClassName', + target_node=atom_property_net.node, + restriction_property=atom_property_net.id, + restriction_net_value=class_net_2.id)} + {restriction_net.add_attribute(target_node=class_net_2.node)} + + + {composite_class_net.construct(base_node=class_net_1.base_node, + node=atom_property_net.base_node, + class_name='?newClassName', + mother_class_net=class_net_1.id, + restriction01=restriction_net.id)} + {composite_class_net.add_attribute(node=class_net_1.node)} + {composite_class_net.add_attribute(node=class_net_2.node)} + """, + 'clause': f""" + # *** Identify Property(arg0:Class, arg1:Class) *** + {atom_property_net.identify_net(core_role='true')} + {atom_property_net.id} amr:role_ARG1 {class_net_1.id}. + {atom_property_net.id} amr:role_ARG2 {class_net_2.id}. + + {class_net_1.identify_net()} + {class_net_2.identify_net()} + + # *** condition: disjoint cover *** + FILTER NOT EXISTS {{ + {class_net_1.id} net:coverNode ?node. + {class_net_2.id} net:coverNode ?node. + }} + + # *** Identify variable label of base leaf *** + {class_net_1.base_node} a amr:AMR_Leaf ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + """, + 'binding': f""" + # -- New Class Name + BIND (CONCAT({class_net_1.class_name}, '-', {atom_property_net.property_name12}) AS ?cn1). + BIND (CONCAT(?cn1, '-', {class_net_2.class_name}) AS ?newClassName). + + {restriction_net.bind_uri(atom_property_net.property_name01, class_net_2.class_name)} + + {composite_class_net.bind_uri('?newClassName', '?varLabel')} + """ +} + + + +# rule_set['create-composite-class-net-from-property-2'] = { +# 'label': "create-composite-class-net-from-property-2", +# 'comment': ("Create Composite Class Net (and Restriction Net): ", +# " (1) from relation between two classes as ARG1 and ARG2, ", +# " (2) with a relation corresponding to Core Role property", +# " (3) in normal direction"), +# 'construction': """ +# # -- New Restriction Net +# ?newRestrictionNet a net:Restriction_Net ; +# net:hasStructure ?sentenceRef ; +# net:coverBaseNode ?baseLeaf ; +# net:coverTargetNode ?propertyLeaf, +# ?nodeOfArg2Net ; +# net:hasRestrictionOnProperty ?propertyNet ; +# net:hasRestrictionNetValue ?arg2Net. + +# # -- New Class Net +# ?newNet a net:Composite_Class_Net ; +# net:hasStructure ?sentenceRef ; +# net:coverBaseNode ?baseLeaf ; +# net:coverTargetNode ?propertyLeaf, +# ?nodeOfArg1Net, +# ?nodeOfArg2Net ; +# net:hasClassName ?newClassName ; +# net:hasMotherClassNet ?arg1Net ; +# net:hasRestriction12 ?newRestrictionNet. + +# # -- Propagation of relations (from nodes to nets) +# ?inRelationRole a net:Relation. +# ?inNet ?inRelationRole ?newNet. +# ?outRelationRole a net:Relation. +# ?newNet ?outRelationRole ?outNet. +# """, +# 'clause': """ +# # -- Identify Property(arg1:Class, arg2:Class) +# ?propertyNet a [rdfs:subClassOf* net:Property_Net] ; +# net:isCoreRoleLinked true ; +# net:hasStructure ?sentenceRef ; +# net:coverNode ?propertyLeaf ; +# net:hasPropertyName12 ?propertyName12. +# ?propertyNet amr:role_ARG1 ?arg1Net. +# ?arg1Net a [rdfs:subClassOf* net:Class_Net] ; +# net:coverBaseNode ?baseLeaf ; +# net:coverNode ?nodeOfArg1Net ; +# net:hasClassName ?arg1Name. +# ?propertyNet amr:role_ARG2 ?arg2Net. +# ?arg2Net a [rdfs:subClassOf* net:Class_Net] ; +# net:coverBaseNode ?arg2Leaf ; +# net:coverNode ?nodeOfArg2Net ; +# net:hasClassName ?arg2Name. + +# # -- condition: disjoint cover +# FILTER NOT EXISTS {?arg1Net net:coverNode ?node. +# ?arg2Net net:coverNode ?node.} + +# # -- 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 Class Name +# BIND (CONCAT(?arg1Name, '-', ?propertyName12) AS ?cn1). +# BIND (CONCAT(?cn1, '-', ?arg2Name) AS ?newClassName). + +# # -- New Restriction Net +# BIND (CONCAT(str(net:), 'restriction') AS ?rn1). +# BIND (CONCAT(?rn1, '_', str(?propertyName12)) AS ?rn2). +# BIND (CONCAT(?rn2, '_', str(?arg2Name)) AS ?rn3). +# BIND (uri(?rn3) AS ?newRestrictionNet). + +# # -- New Class Net +# BIND (CONCAT(str(net:), 'compositeClass') AS ?n1). +# BIND (CONCAT(?n1, '_', ?newClassName) AS ?n2). +# BIND (uri(?n2) AS ?newNet). +# """ +# } + + + + +rule_set['create-composite-class-net-from-property-3'] = { + 'label': "create-composite-class-net-from-property-3", + 'comment': ("Create Composite Class Net: ", + " (1) complete Composite Class Net for relation propagation"), + 'construction': f""" + {composite_class_net.define_structure()} + {composite_class_net.propagate_relations()} + """, + 'clause': f""" + # *** Identify CompositeClass in progress step INIT *** + {composite_class_net.identify_net()} + {composite_class_net.filter_already_processed_net(Net.RELATION_PROPAGATED)} + + # *** Complete clauses for net construction *** + {composite_class_net.complete_clauses_for_construction()} + """, + 'binding': f""" + """ +} + +# ************************************ +# *** OLD *** +# Dropping this rule for non-core roles. +# Cases treated as core roles, if reification, or as linguistic phenomena if not. +# *********************************** +# rule_set['create-composite-class-net-from-property-4'] = { +# 'label': "create-composite-class-net-from-property-4", +# 'comment': ("Create Composite Class Net (and Restriction Net): ", +# " (1) from relation between two classes, ", +# " (2) with a relation corresponding to Non-Core Role property"), +# 'construction': """ +# # -- New Restriction Net +# ?newRestrictionNet a net:Restriction_Net ; +# net:hasStructure ?sentenceRef ; +# net:coverBaseNode ?baseLeaf ; +# net:coverTargetNode ?argNodeOfBaseNet, ?nodeOfArgNet ; +# net:hasRestrictionOnProperty ?propertyNet ; +# net:hasRestrictionNetValue ?argNet. + +# # -- New Class Net +# ?newClassNet a net:Composite_Class_Net ; +# net:hasStructure ?sentenceRef ; +# net:coverBaseNode ?baseLeaf ; +# net:coverNode ?nodeOfBaseNet, ?nodeOfArgNet ; +# net:hasClassName ?newClassName ; +# net:hasMotherClassNet ?baseNet ; +# net:hasRestriction ?newRestrictionNet. + +# # -- Propagation of relations (from nodes to nets) +# ?inRelationRole a net:Relation. +# ?inNet ?inRelationRole ?newNet. +# ?outRelationRole a net:Relation. +# ?newNet ?outRelationRole ?outNet. +# """, +# 'clause': """ +# # -- Identify Property(Class, Class) +# ?propertyNet a [rdfs:subClassOf* net:Property_Net]; +# net:isCoreRoleLinked false ; +# net:hasStructure ?sentenceRef ; +# net:coverBaseNode ?baseLeaf ; +# # -- old --- net:targetArgumentNode ?argLeaf ; +# net:hasPropertyRole ?propertyRole ; +# net:hasPropertyName ?propertyName. +# # -- old --- FILTER ( ?propertyName != 'hasFeature' ). +# ?baseNet ?propertyRole ?argNet. +# ?baseNet a [rdfs:subClassOf* net:Class_Net] ; +# net:coverBaseNode ?baseLeaf ; +# net:coverNode ?nodeOfBaseNet ; +# net:hasClassName ?baseName. +# ?argNet a [rdfs:subClassOf* net:Class_Net] ; +# net:coverNode ?nodeOfArgNet ; +# net:hasClassName ?argName. + +# # -- condition: disjoint cover +# FILTER NOT EXISTS {?baseNet net:coverNode ?node. +# ?argNet net:coverNode ?node.} + +# # -- 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 Class Name +# BIND (CONCAT(str(?baseName), '-', str(?propertyName)) AS ?cn1). +# BIND (CONCAT(?cn1, '-', str(?argName)) AS ?newClassName1). +# BIND (CONCAT(str(?argName), '-', str(?baseName)) AS ?newClassName2). +# BIND (IF (?propertyName != 'hasFeature', +# ?newClassName1, +# ?newClassName2) +# AS ?newClassName). + +# # -- New Restriction Net +# BIND (CONCAT(str(net:), 'restriction') AS ?rn1). +# BIND (CONCAT(?rn1, '_', str(?propertyName)) AS ?rn2). +# BIND (CONCAT(?rn2, '_', str(?argName)) AS ?rn3). +# BIND (uri(?rn3) AS ?newRestrictionNet). + +# # -- New Class Net +# BIND (CONCAT(str(net:), 'compositeClass') AS ?n1). +# BIND (CONCAT(?n1, '_', ?newClassName) AS ?n2). +# BIND (uri(?n2) AS ?newClassNet). +# """ +# } + + +#============================================================================== +# Development Test +#============================================================================== + +if __name__ == '__main__': + + print('\n' + ' *** Development Test ***') + + print('\n' + ' -- Test Query') + rule = rule_set['create-composite-class-net-from-property-3'] + 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/tenet/scheme/amr_master_rule/nov_transduction/composite_class_extraction_2.py b/tenet/scheme/amr_master_rule/nov_transduction/composite_class_extraction_2.py new file mode 100644 index 0000000000000000000000000000000000000000..a662f621f1ee6a0e3822a3c04d170796853a58ff --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/composite_class_extraction_2.py @@ -0,0 +1,291 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Net Expansion: Composite Class Net from Phenomena Net +# --------------------------------------------- + +rule_set['create-composite-class-net-from-phenomena-1'] = { + 'label': "create-composite-class-net-from-phenomena-1", + 'comment': ("Create Composite Class Net from relations: ", + " (1) between classes and DEGREE phenomena", + " (2) targetting attribute (:ARG2) and degree (:ARG3)"), + 'construction': """ + # -- New Class Net (on attributeNet base leaf) + ?newNet a net:Composite_Class_Net ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:coverArgNode ?degreeLeaf ; + net:hasNaming ?newClassName ; + net:hasClassName ?newClassName ; + net:hasMotherClassNet ?attributeNet. + ?degreePhenomenaNet net:targetSubAttribute ?newNet. + + # -- Propagation of relations (from nodes to nets) + ?inRelationRole a net:Relation. + ?inNet ?inRelationRole ?newNet. + ?outRelationRole a net:Relation. + ?newNet ?outRelationRole ?outNet. + """, + 'clause': """ + # -- Identify degree(attribute, degree) + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetAttribute ?attributeNet ; + net:targetDegree ?degreeNet ; + net:hasPhenomenaType amr:phenomena_degree. + ?attributeNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?baseLeaf ; + net:hasClassName ?attributeName. + ?degreeNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?degreeLeaf ; + net:hasClassName ?degreeName. + + # -- 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 Class Name + BIND (CONCAT(str(?degreeName), '-', + str(?attributeName)) AS ?newClassName). + + # -- New Class Net + BIND (CONCAT(str(net:), 'compositeClass') AS ?n1). + BIND (CONCAT(?n1, '_', ?newClassName) AS ?n2). + BIND (uri(?n2) AS ?newNet). + """ +} + +rule_set['create-composite-class-net-from-phenomena-2'] = { + 'label': "create-composite-class-net-from-phenomena-2", + 'comment': ("Create Composite Class Net from relations: ", + " (1) between classes and DEGREE phenomena", + " (2) targetting domain (:ARG1) and attribute (:ARG2)"), + 'construction': """ + # -- New Class Net (on domainNet base leaf) + ?newNet a net:Composite_Class_Net ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:coverArgNode ?attributeLeaf ; + net:hasNaming ?newClassName ; + net:hasClassName ?newClassName ; + net:hasMotherClassNet ?domainNet. + ?degreePhenomenaNet net:targetSubDomain ?newNet. + + # -- Propagation of relations (from nodes to nets) + ?inRelationRole a net:Relation. + ?inNet ?inRelationRole ?newNet. + ?outRelationRole a net:Relation. + ?newNet ?outRelationRole ?outNet. + """, + 'clause': """ + # -- Identify degree(domain, attribute) + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetDomain ?domainNet ; + net:targetAttribute ?attributeNet ; + net:hasPhenomenaType amr:phenomena_degree. + ?domainNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?baseLeaf ; + net:hasClassName ?domainName. + ?attributeNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverNode ?attributeLeaf ; + net:hasClassName ?attributeName. + + # -- 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 Class Name + BIND (CONCAT(str(?attributeName), '-', + str(?domainName)) AS ?newClassName). + + # -- New Class Net + BIND (CONCAT(str(net:), 'compositeClass') AS ?n1). + BIND (CONCAT(?n1, '_', ?newClassName) AS ?n2). + BIND (uri(?n2) AS ?newNet). + """ +} + +rule_set['create-composite-class-net-from-phenomena-3'] = { + 'label': "create-composite-class-net-from-phenomena-3", + 'comment': ("Create Composite Class Net from relations: ", + " (1) between classes and DEGREE phenomena", + " (2) targetting sub-domain and sub-attribute"), + 'construction': """ + # -- New Class Net (on domainNet base leaf) + ?newNet a net:Composite_Class_Net ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:coverArgNode ?subAttributeLeaf ; + net:hasNaming ?newClassName ; + net:hasClassName ?newClassName ; + net:hasMotherClassNet ?subDomainNet. + ?degreePhenomenaNet net:targetSubDomain ?newNet. + + # -- Propagation of relations (from nodes to nets) + ?inRelationRole a net:Relation. + ?inNet ?inRelationRole ?newNet. + ?outRelationRole a net:Relation. + ?newNet ?outRelationRole ?outNet. + """, + 'clause': """ + # -- Identify degree(sub-domain, sub-attribute) + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetDomain ?domainNet ; + net:targetSubDomain ?subDomainNet ; + net:targetSubAttribute ?subAttributeNet ; + net:hasPhenomenaType amr:phenomena_degree. + ?subDomainNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?baseLeaf ; + net:hasClassName ?subDomainName. + ?subAttributeNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverNode ?subAttributeLeaf ; + net:hasClassName ?subAttributeName. + + # -- 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 Class Name + BIND (CONCAT(str(?subAttributeName), '-', + str(?subDomainName)) AS ?newClassName). + + # -- New Class Net + BIND (CONCAT(str(net:), 'compositeClass') AS ?n1). + BIND (CONCAT(?n1, '_', ?newClassName) AS ?n2). + BIND (uri(?n2) AS ?newNet). + """ +} + +rule_set['create-composite-class-net-from-phenomena-4'] = { + 'label': "create-composite-class-net-from-phenomena-4", + 'comment': ("Create Composite Class Net from relations: ", + " (1) between classes and DEGREE phenomena", + " (2) targetting sub-domain and superlative"), + 'construction': """ + # -- New Class Net (on subDomainNet base leaf) + ?newNet a net:Composite_Class_Net ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?superlativeLeaf ; + net:coverArgNode ?baseLeaf ; + net:hasNaming ?newClassName ; + net:hasClassName ?newClassName ; + net:hasMotherClassNet ?superlativeNet. + ?degreePhenomenaNet net:targetSubDomain ?newNet. + + # -- Propagation of relations (from nodes to nets) + ?inRelationRole a net:Relation. + ?inNet ?inRelationRole ?newNet. + ?outRelationRole a net:Relation. + ?newNet ?outRelationRole ?outNet. + """, + 'clause': """ + # -- Identify degree(sub-domain, superlative) + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetSubDomain ?subDomainNet ; + net:targetSuperlative ?superlativeNet ; + net:hasPhenomenaType amr:phenomena_degree. + ?subDomainNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?baseLeaf ; + net:coverNodeCount ?subDomainPrecision ; + net:hasClassName ?subDomainName. + FILTER NOT EXISTS { + ?otherSubDomainNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?baseLeaf ; + net:coverNodeCount ?otherSubDomainPrecision. + FILTER (?otherSubDomainPrecision > ?subDomainPrecision). + } + ?superlativeNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?superlativeLeaf ; + net:coverNodeCount ?superlativePrecision ; + net:hasClassName ?superlativeName. + FILTER NOT EXISTS { + ?otherSuperlativeNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?superlativeLeaf ; + net:coverNodeCount ?otherSuperlativePrecision. + FILTER (?otherSuperlativePrecision > ?superlativePrecision). + } + + # -- 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 Class Name + BIND (CONCAT(str(?subDomainName), '-in-', + str(?superlativeName)) AS ?newClassName). + + # -- New Class Net + BIND (CONCAT(str(net:), 'compositeClass') AS ?n1). + BIND (CONCAT(?n1, '_', ?newClassName) AS ?n2). + BIND (uri(?n2) AS ?newNet). + """ +} \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/nov_transduction/composite_property_extraction.py b/tenet/scheme/amr_master_rule/nov_transduction/composite_property_extraction.py new file mode 100644 index 0000000000000000000000000000000000000000..ae5fa0b1215648df4b3c13161ba45b578fdbd184 --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/composite_property_extraction.py @@ -0,0 +1,228 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Net Expansion: Composite Property Net from Property Net +# --------------------------------------------- + +rule_set['create-composite-property-net-from-property-1'] = { + 'label': "create-composite-class-net-from-property-1", + 'comment': ("Create Composite Property Net from relations: ", + " (1) between two core properties", + " (2) with :ARG1 relation"), + 'construction': """ + # -- New Property Net + ?newNet a net:Composite_Property_Net ; + net:isCoreRoleLinked true ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:coverArgNode ?property2Leaf ; + net:hasPropertyType ?property1Type ; + net:hasNaming ?newPropertyName ; + net:hasPropertyName ?newPropertyName ; + net:hasMotherClassNet ?property2Net. + #net:hasRestriction ?restrictionNet. + + # -- Propagation of relations (from nodes to nets) + ?inRelationRole a net:Relation. + ?inNet ?inRelationRole ?newNet. + ?outRelationRole a net:Relation. + ?newNet ?outRelationRole ?outNet. + """, + 'clause': """ + # -- Identify ARG1(p1:Property, p2:Property) + ?property1Net a [rdfs:subClassOf* net:Property_Net] ; + net:isCoreRoleLinked true ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:hasPropertyType ?property1Type ; + net:hasPropertyName ?property1Name. + ?baseLeaf ?r1 ?property2Leaf. + ?r1 amr:hasAmrRole amr:role_ARG1. + ?property2Net a [rdfs:subClassOf* net:Property_Net] ; + net:isCoreRoleLinked true ; + net:coverBaseNode ?property2Leaf ; + net:hasPropertyName ?property2Name. + + # -- condition: disjoint cover + FILTER NOT EXISTS {?property1Leaf net:coverNode ?node. + ?property2Leaf net:coverNode ?node.} + + # -- 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 Property Name + BIND (CONCAT(?property1Name, '-', ?property2Name) AS ?newPropertyName). + + # -- New Property Net + BIND (CONCAT(str(net:), 'compositeProperty') AS ?n1). + BIND (CONCAT(?n1, '_', ?newPropertyName) AS ?n2). + BIND (uri(?n2) AS ?newNet). + """ +} + +rule_set['create-composite-property-net-from-property-2'] = { + 'label': "create-composite-class-net-from-property-2", + 'comment': ("Create Composite Property Net from relations: ", + " (1) between two core properties", + " (2) with manner property on the same leaf of left property"), + 'construction': """ + # -- New Property Net + ?newNet a net:Composite_Property_Net ; + net:isCoreRoleLinked true ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:coverArgNode ?property2Leaf ; + net:hasPropertyType ?property1Type ; + net:hasNaming ?newPropertyName ; + net:hasPropertyName ?newPropertyName ; + net:hasMotherClassNet ?property1Net. + #net:hasRestriction ?restrictionNet. + + # -- Propagation of relations (from nodes to nets) + ?inRelationRole a net:Relation. + ?inNet ?inRelationRole ?newNet. + ?outRelationRole a net:Relation. + ?newNet ?outRelationRole ?outNet. + """, + 'clause': """ + # -- Identify cover(p1:Property, leaf1) and cover(m:Manner, leaf1) + ?property1Net a [rdfs:subClassOf* net:Property_Net] ; # property 1 + net:isCoreRoleLinked true ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:hasPropertyType ?property1Type ; + net:hasPropertyName ?property1Name. + ?mannerPropertyNet a [rdfs:subClassOf* net:Property_Net] ; # manner property + net:isCoreRoleLinked true ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:hasPropertyType ?mannerPropertyType ; + net:hasPropertyName ?mannerPropertyName. + + # -- Identify :manner(p2:Property) + ?mannerPropertyNet amr:role_manner ?property2Net. + ?property2Net a [rdfs:subClassOf* net:Property_Net] ; + net:isCoreRoleLinked true ; + net:coverBaseNode ?property2Leaf ; + net:hasPropertyName ?property2Name. + + # -- condition: disjoint cover + FILTER NOT EXISTS {?sameBaseLeaf net:coverNode ?node. + ?property2Leaf net:coverNode ?node.} + + # -- 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 Property Name + BIND (CONCAT(?property2Name, '-', ?property1Name) AS ?newPropertyName). + # -- New Property Net + BIND (CONCAT(str(net:), 'compositeProperty') AS ?n1). + BIND (CONCAT(?n1, '_', ?newPropertyName) AS ?n2). + BIND (uri(?n2) AS ?newNet). + """ +} + + +# --------------------------------------------- +# Net Expansion: Add Restriction to Class Net from Property Net +# --------------------------------------------- + +rule_set['add-restriction-to-class-net-from-property-1'] = { + 'label': "add-restriction-to-class-net-from-property-1", + 'comment': ("Create and add a Restriction Net: ", + " (1) from relation between a class and an individual, ", + " (2) with a relation corresponding to Non-Core Role property"), + 'construction': """ + # -- New Restriction Net + ?newNet a net:Restriction_Net ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:coverTargetNode ?argNodeOfBaseNet, ?nodeOfArgNet ; + net:hasRestrictionOnProperty ?propertyNet ; + net:hasRestrictionNetValue ?argNet. + + # -- New restriction relation + ?baseNet net:hasRestriction ?newNet. + + # -- Propagation of relations (from nodes to nets) + ?inRelationRole a net:Relation. + ?inNet ?inRelationRole ?newNet. + ?outRelationRole a net:Relation. + ?newNet ?outRelationRole ?outNet. + """, + 'clause': """ + # -- Identify property(Class, Individual) + ?propertyNet a [rdfs:subClassOf* net:Property_Net]; + net:isCoreRoleLinked false ; + net:hasStructure ?sentenceRef ; + net:coverBaseNode ?baseLeaf ; + net:hasPropertyRole ?propertyRole ; + net:hasPropertyName ?propertyName. + ?baseNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?baseLeaf ; + net:coverNode ?nodeOfBaseNet ; + net:hasClassName ?baseName. + ?argNet a net:Individual_Net ; + net:coverNode ?nodeOfArgNet ; + net:hasIndividualLabel ?argLabel. + ?baseNet ?propertyRole ?argNet. + + # -- condition: disjoint cover + FILTER NOT EXISTS {?baseNet net:coverNode ?node. + ?argNet net:coverNode ?node.} + + # -- 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 Restriction Net + BIND (CONCAT(str(net:), 'restriction') AS ?rn1). + BIND (CONCAT(?rn1, '_', str(?propertyName)) AS ?rn2). + BIND (CONCAT(?rn2, '_', str(?argLabel)) AS ?rn3). + BIND (uri(?rn3) AS ?newNet). + """ +} \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/nov_transduction/phenomena_application_and.py b/tenet/scheme/amr_master_rule/nov_transduction/phenomena_application_and.py new file mode 100644 index 0000000000000000000000000000000000000000..2b0db73264e0a3932c58eb79add6722002c4b67b --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/phenomena_application_and.py @@ -0,0 +1,254 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# Query Builder Imports +#============================================================================== + +#import query_builder.construct as construct +from query_builder.builders import * +from query_builder.element.net import Net + + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + +# --------------------------------------------- +# Net Expansion: Conjunction Phenomena Net +# --------------------------------------------- + +rule_set['and-conjunction-phenomena-application-1'] = { + 'label': "and-conjunction-phenomena-application-1", + 'comment': ("Apply conjunction phenomena, step 1: ", + " (1) create logical set", + " (2) FROM and-conjunction linking some nets and a property"), + 'construction': f""" + {logical_set_net.construct(base_node=phenomena_net.base_node, + logical_constraint='"AND"', + property_net=atom_property_net.id, + content_net_1='?contentNet1')} + {logical_set_net.add_attribute(content_net_2='?contentNet2')} + {logical_set_net.add_attribute(content_net='?contentNet1')} + {logical_set_net.add_attribute(content_net='?contentNet2')} + {logical_set_net.add_attribute(content_net='?contentNet3')} + {logical_set_net.add_attribute(content_net='?contentNet4')} + {logical_set_net.add_attribute(content_net='?contentNet5')} + {logical_set_net.add_attribute(content_net='?contentNet6')} + {logical_set_net.add_attribute(content_net='?contentNet7')} + {logical_set_net.add_attribute(content_net='?contentNet8')} + {logical_set_net.add_attribute(content_net='?contentNet9')} + + {logical_set_net.propagate_relations()} + """, + 'clause': f""" + + # *** Identify Property(-, arg1:PhenomenaNet) *** + + {atom_property_net.identify_net(core_role='true')} + {atom_property_net.id} amr:role_ARG1 {phenomena_net.id}. + + + # *** Identify Phenomena(AND-conjunction, contentNet*) *** + + {phenomena_net.identify_net(phenomena_type='amr:phenomena_conjunction_and')} + + # -- old --- ?relationOp rdfs:subClassOf* amr:AMR_Op_Role. + {phenomena_net.identify_operator('1', '?contentNet')} + {phenomena_net.identify_optional_operator('2', '?contentNet')} + {phenomena_net.identify_optional_operator('3', '?contentNet')} + {phenomena_net.identify_optional_operator('4', '?contentNet')} + {phenomena_net.identify_optional_operator('5', '?contentNet')} + {phenomena_net.identify_optional_operator('6', '?contentNet')} + {phenomena_net.identify_optional_operator('7', '?contentNet')} + {phenomena_net.identify_optional_operator('8', '?contentNet')} + {phenomena_net.identify_optional_operator('9', '?contentNet')} + + + # *** Identify variable label of base leaf *** + {phenomena_net.base_node} a amr:AMR_Leaf ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + + {logical_set_net.complete_clauses_for_construction(phenomena_net.base_node)} + """, + 'binding': f""" + {logical_set_net.bind_uri(phenomena_net.phenomena_ref, '?varLabel')} + """ +} + +rule_set['and-conjunction-phenomena-application-2'] = { + 'label': "and-conjunction-phenomena-application-2", + 'comment': ("Apply conjunction phenomena (step 2): ", + " (1) complete Logical Set Net for naming"), + 'construction': f""" + {logical_set_net.define_naming()} + """, + 'clause': f""" + + # *** Identify LogicalSet Net *** + {logical_set_net.identify_net_without_optional_attribute( + property_net=property_net.id, + content_net_1=class_net_1.id, + content_net_2=class_net_2.id)} + + + # *** Identify property and classes *** + {property_net.identify_net(core_role='true')} + {class_net_1.identify_net()} + {class_net_2.identify_net()} + + """, + 'binding': f""" + {logical_set_net.bind_naming(property_net.property_name, + class_net_1.class_name, + class_net_2.class_name)} + """ +} + +rule_set['and-conjunction-phenomena-application-3'] = { + 'label': "and-conjunction-phenomena-application-3", + 'comment': ("Apply conjunction phenomena (step 3): ", + " (1) complete Logical Set Net with restriction(s)"), + 'construction': f""" + + {restriction_net.construct(restriction_property=property_net.id, + restriction_net_value=class_net.id)} + {restriction_net.add_attribute(node=property_net.node)} + {restriction_net.add_attribute(node=logical_set_net.node)} + {restriction_net.add_attribute(node=class_net.node)} + + {logical_set_net.add_attribute(restriction=restriction_net.id)} + """, + 'clause': f""" + # *** Identify LogicalSet Net *** + {logical_set_net.identify_net(property_net=property_net.id)} + {logical_set_net.identify_content_net(class_net.id)} + + # *** Identify property and classes *** + {property_net.identify_net(core_role='true')} + {class_net.identify_net()} + """, + 'binding': f""" + {restriction_net.bind_uri(property_net.property_name, class_net.class_name)} + """ +} + +rule_set['and-conjunction-phenomena-application-4'] = { + 'label': "and-conjunction-phenomena-application-4", + 'comment': ("Apply conjunction phenomena (step 4): ", + " (1) create composite class net", + " (2) FROM property linking class and logical set"), + 'construction': f""" + {composite_class_net.construct(base_node=class_net_0.base_node, + naming='?newClassName', + class_name='?newClassName', + mother_class_net=class_net_0.id)} + {composite_class_net.compose(class_net_0, property_net, logical_set_net)} + """, + 'clause': f""" + # *** Identify Property(arg0:Class, arg1:LogicalSet) *** + {property_net.identify_net(core_role='true')} + {property_net.id} amr:role_ARG0 {class_net_0.id}. + {property_net.id} amr:role_ARG1 {logical_set_net.id}. + + # *** Identify class and logical set *** + {class_net_0.identify_net()} + {logical_set_net.identify_net(logical_constraint='"AND"')} + + # *** condition: disjoint cover *** + FILTER NOT EXISTS {{ + {class_net_0.id} net:coverNode ?node. + {logical_set_net.id} net:coverNode ?node. + }} + + # *** Identify variable label of base leaf *** + {class_net_0.base_node} a amr:AMR_Leaf ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + """, + 'binding': f""" + # -- New Class Name + BIND (CONCAT({class_net_0.class_name}, '-', {logical_set_net.naming}) AS ?newClassName). + + {composite_class_net.bind_uri('?newClassName', '?varLabel')} + """ +} + +rule_set['and-conjunction-phenomena-application-5'] = { + 'label': "and-conjunction-phenomena-application-5", + 'comment': ("Apply conjunction phenomena (step 5): ", + " (1) complete Logical Set Net for relation propagation"), + 'construction': f""" + {composite_class_net.define_structure()} + {composite_class_net.propagate_relations()} + """, + 'clause': f""" + # *** Identify CompositeClass with a LogicalSet composante *** + {composite_class_net.identify_net()} + {composite_class_net.filter_already_processed_net(Net.RELATION_PROPAGATED)} + + # *** Complete clauses for net construction *** + {composite_class_net.complete_clauses_for_construction()} + """, + 'binding': f""" + """ +} + +rule_set['and-conjunction-phenomena-application-6'] = { + 'label': "and-conjunction-phenomena-application-6", + 'comment': ("Apply conjunction phenomena (step 6): ", + " (1) complete Logical Set Net by adding restrictions"), + 'construction': f""" + {composite_class_net.add_attribute(restriction01=restriction_net.id)} + """, + 'clause': f""" + # *** Identify CompositeClass in progress step INIT *** + {composite_class_net.identify_net()} + {composite_class_net.filter_already_processed_net(Net.RESTRICTION_ADDED)} + {logical_set_net.identify_net()} + {composite_class_net.identify_composante(logical_set_net.id)} + + # *** Identify Restriction *** + {restriction_net.identify_net()} + {logical_set_net.identify_restriction(restriction_net.id)} + """, + 'binding': f""" + """ +} + + +# --------------------------------------------- +# *** Under Development *** New Rule +# --------------------------------------------- + +# -- Useful query builder(s) +# * TODO * property_net = PropertyNet() +# * TODO * class_net_0 = ClassNet(0) +# * TODO * phenomena_net = PhenomenaNet() +# * TODO * and_composite_class_net = AndCompositeClassNet() + +def analyze_phenomena_and(): + rule = 'NewRule()' # !!! TODO !!! + + # rule.clause(f'{property_net.identify_net(core_role="true")}') + # rule.clause(f'{property_net.id} amr:role_ARG0 {class_net_0.id}.') + # rule.clause(f'{property_net.id} amr:role_ARG1 {phenomena_net.id}.') + # rule.clause(f'{phenomena_net.identify_net(phenomena_type='amr:phenomena_conjunction_and')}') + + # rule.operate(f'{and_composite_class_net.construct(*TODO*)}') + + # * TODO * add restrictions for and_composite_class_net --op--> class_net + + # * TODO * rule.operate(and_composite_class_net.complete_clauses_for_construction()) + + return rule diff --git a/tenet/scheme/amr_master_rule/nov_transduction/phenomena_application_mod.py b/tenet/scheme/amr_master_rule/nov_transduction/phenomena_application_mod.py new file mode 100644 index 0000000000000000000000000000000000000000..e22d673535632e5fd24a126ea9690e113432ff51 --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/phenomena_application_mod.py @@ -0,0 +1,133 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# Query Builder Imports +#============================================================================== + +#import query_builder.construct as construct +from query_builder.builders import * +from query_builder.element.net import Net + + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Net Expansion: Mod Phenomena Application +# --------------------------------------------- + +rule_set['mod-phenomena-application-1'] = { + 'label': "mod-phenomena-application-1", + 'comment': ("Apply mod phenomena (step 1) to: ", + " (+) initialize composite class construction. "), + 'construction': f""" + {composite_class_net.construct(base_node=class_net_1.base_node, + class_name='?newClassName', + mother_class_net=class_net_1.id)} + {composite_class_net.compose(class_net_1, class_net_2)} + """, + 'clause': f""" + # *** Identify Mod(c1:Class, c2:Class) *** + {class_net_1.identify_net()} + {class_net_1.identify_relation('amr:role_mod', class_net_2.id)} + {class_net_2.identify_net()} + + # *** Identify variable label of base leaf *** + {class_net_1.base_node} a amr:AMR_Leaf ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + """, + 'binding': f""" + # -- New Class Name + BIND (CONCAT({class_net_2.class_name}, '-', {class_net_1.class_name}) + AS ?newClassName). + + {composite_class_net.bind_uri('?newClassName', '?varLabel')} + """ +} + +rule_set['mod-phenomena-application-2'] = { + 'label': "mod-phenomena-application-2", + 'comment': ("Apply mod phenomena (step 2) to: ", + " (+) complete Composite Class Net for relation propagation"), + 'construction': f""" + {composite_class_net.define_structure()} + {composite_class_net.propagate_relations()} + """, + 'clause': f""" + # *** Identify CompositeClass without relation propagated *** + {composite_class_net.identify_net()} + {composite_class_net.filter_already_processed_net(Net.RELATION_PROPAGATED)} + + # *** Complete clauses for net construction *** + {composite_class_net.complete_clauses_for_construction()} + """, + 'binding': f""" + """ +} + +rule_set['mod-phenomena-application-3'] = { + 'label': "mod-phenomena-application-3", + 'comment': ("Apply mod phenomena (step 3) to: ", + " (+) initialize Individual Net construction"), + 'construction': f""" + {individual_net.construct(base_node=class_net_2.base_node, + base_class_name='"Feature"', + individual_label='?newIndividualLabel')} + {individual_net.compose(class_net_2)} + {individual_net.define_structure()} + """, + 'clause': f""" + # *** Identify Mod(:Class, c2:Class) *** + ?net amr:role_mod {class_net_2.id}. + {class_net_2.identify_net()} + + # *** Identify variable label of base leaf *** + {class_net_2.base_node} a amr:AMR_Leaf ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + + # *** Complete clauses for net construction *** + {individual_net.complete_clauses_for_construction()} + """, + 'binding': f""" + # -- New Individual Label + BIND (STR({class_net_2.class_name}) AS ?newIndividualLabel). + + {individual_net.bind_uri('?newIndividualLabel', '?varLabel')} + """ +} + +rule_set['mod-phenomena-application-4'] = { + 'label': "mod-phenomena-application-4", + 'comment': ("Apply mod phenomena (step 4) to: ", + " (4) complete Composite Class Net by adding restrictions"), + 'construction': f""" + {composite_class_net.add_attribute(restriction01=restriction_net.id)} + """, + 'clause': f""" + # *** Identify CompositeClass in progress step INIT *** + {composite_class_net.identify_net()} + {composite_class_net.filter_already_processed_net(Net.RESTRICTION_ADDED)} + {logical_set_net.identify_net()} + {composite_class_net.identify_composante(logical_set_net.id)} + + # *** Identify Restriction *** + {restriction_net.identify_net()} + {logical_set_net.identify_restriction(restriction_net.id)} + """, + 'binding': f""" + """ +} diff --git a/tenet/scheme/amr_master_rule/nov_transduction/phenomena_application_polarity.py b/tenet/scheme/amr_master_rule/nov_transduction/phenomena_application_polarity.py new file mode 100644 index 0000000000000000000000000000000000000000..b55d9b428f75a694c83ff62e1d74729b26d5fb9c --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/phenomena_application_polarity.py @@ -0,0 +1,69 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# Query Builder Imports +#============================================================================== + +#import query_builder.construct as construct +from query_builder.builders import * +from query_builder.element.net import Net + + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Net Expansion: Polarity Phenomena Application +# --------------------------------------------- + +rule_set['nov-polarity-phenomena-application'] = { + 'label': "polarity-phenomena-application", + 'comment': ("Apply polarity phenomena to: ", + " (1) polarity relation on a property class. "), + 'construction': f""" + + # !!! TODO: restriction for negative polarity !!! + + {composite_property_net.construct(base_node=atom_property_net.base_node, + naming='?newPropertyName', + property_name='?newPropertyName')} + + {composite_property_net.propagate_relations()} + + {atom_property_net.deprecate()} + + """, + 'clause': f""" + # *** Identify Polarity(p0:Property, 'negative') *** + + {atom_property_net.identify_net(core_role='true')} + + {atom_property_net.identify_relation('amr:role_polarity', value_net.id)} + {value_net.identify_net(value_label="'negative'")} + + # *** Identify variable label of base leaf *** + {atom_property_net.base_node} a amr:AMR_Leaf ; + amr:hasVariable ?variable. + ?variable amr:label ?varLabel. + + {composite_property_net.complete_clauses_for_construction(atom_property_net.base_node)} + """, + 'binding': f""" + # -- New Property Name + BIND (CONCAT('not', '-', {atom_property_net.property_name}) AS ?newPropertyName). + + {composite_property_net.bind_uri('?newPropertyName', '?varLabel')} + """ +} diff --git a/tenet/scheme/amr_master_rule/nov_transduction/phenomena_checking.py b/tenet/scheme/amr_master_rule/nov_transduction/phenomena_checking.py new file mode 100644 index 0000000000000000000000000000000000000000..4218333e9fda1ebfb5bf9ca3e2c1f677ad975599 --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/phenomena_checking.py @@ -0,0 +1,172 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Net Expansion: Conjunction Phenomena Net +# --------------------------------------------- + +rule_set['expand-and-or-conjunction-phenomena-net'] = { + 'label': "expand-and-conjunction-phenomena-net", + 'comment': ("Propagate relations for AND/OR conjunction net with: ", + " (1) incoming relation", + " (2) outgoing :op relation"), + 'construction': """ + ?leftNet ?incomingRelation ?rightNet. + """, + 'clause': """ + ?phenomenaNet a net:Phenomena_Net ; + net:hasPhenomenaType ?phenomenaType. + FILTER (?phenomenaType = amr:phenomena_conjunction_and || + ?phenomenaType = amr:phenomena_conjunction_or). + ?leftNet ?incomingRelation ?phenomenaNet. + ?phenomenaNet ?relationOp ?rightNet. + ?relationOp rdfs:subClassOf* amr:AMR_Op_Role. + """, + 'binding': """ + """ +} + + +# --------------------------------------------- +# Net Expansion: Degree Phenomena Net +# --------------------------------------------- + +rule_set['expand-degree-phenomena-net-1'] = { + 'label': "expand-degree-phenomena-net-1", + 'comment': ("Expand Degree Phenomena Net with: ", + " domain corresponding to :ARG1"), + 'construction': """ + ?degreePhenomenaNet net:targetDomain ?argTargetClassNet. + """, + 'clause': """ + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetArgumentNode ?argTargetLeaf ; + net:hasPhenomenaType amr:phenomena_degree. + ?argTargetClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?argTargetLeaf. + ?phenomenaLeaf ?argEdge ?argTargetLeaf. + ?argEdge amr:hasAmrRole amr:role_ARG1. + """, + 'binding': """ + """ +} + +rule_set['expand-degree-phenomena-net-2'] = { + 'label': "expand-degree-phenomena-net-2", + 'comment': ("Expand Degree Phenomena Net with: ", + " attribute corresponding to :ARG2"), + 'construction': """ + ?degreePhenomenaNet net:targetAttribute ?argTargetClassNet. + """, + 'clause': """ + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetArgumentNode ?argTargetLeaf ; + net:hasPhenomenaType amr:phenomena_degree. + ?argTargetClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?argTargetLeaf. + ?phenomenaLeaf ?argEdge ?argTargetLeaf. + ?argEdge amr:hasAmrRole amr:role_ARG2. + """, + 'binding': """ + """ +} + +rule_set['expand-degree-phenomena-net-3'] = { + 'label': "expand-degree-phenomena-net-3", + 'comment': ("Expand Degree Phenomena Net with: ", + " degree corresponding to :ARG3"), + 'construction': """ + ?degreePhenomenaNet net:targetDegree ?argTargetClassNet. + """, + 'clause': """ + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetArgumentNode ?argTargetLeaf ; + net:hasPhenomenaType amr:phenomena_degree. + ?argTargetClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?argTargetLeaf. + ?phenomenaLeaf ?argEdge ?argTargetLeaf. + ?argEdge amr:hasAmrRole amr:role_ARG3. + """, + 'binding': """ + """ +} + +rule_set['expand-degree-phenomena-net-4'] = { + 'label': "expand-degree-phenomena-net-4", + 'comment': ("Expand Degree Phenomena Net with: ", + " range corresponding to :ARG4"), + 'construction': """ + ?degreePhenomenaNet net:targetRange ?argTargetClassNet. + """, + 'clause': """ + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetArgumentNode ?argTargetLeaf ; + net:hasPhenomenaType amr:phenomena_degree. + ?argTargetClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?argTargetLeaf. + ?phenomenaLeaf ?argEdge ?argTargetLeaf. + ?argEdge amr:hasAmrRole amr:role_ARG4. + """, + 'binding': """ + """ +} + +rule_set['expand-degree-phenomena-net-5'] = { + 'label': "expand-degree-phenomena-net-5", + 'comment': ("Expand Degree Phenomena Net with: ", + " superlative corresponding to :ARG5"), + 'construction': """ + ?degreePhenomenaNet net:targetSuperlative ?argTargetClassNet. + """, + 'clause': """ + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetArgumentNode ?argTargetLeaf ; + net:hasPhenomenaType amr:phenomena_degree. + ?argTargetClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?argTargetLeaf. + ?phenomenaLeaf ?argEdge ?argTargetLeaf. + ?argEdge amr:hasAmrRole amr:role_ARG5. + """, + 'binding': """ + """ +} + +rule_set['expand-degree-phenomena-net-6'] = { + 'label': "expand-degree-phenomena-net-6", + 'comment': ("Expand Degree Phenomena Net with: ", + " consequence corresponding to :ARG6"), + 'construction': """ + ?degreePhenomenaNet net:targetConsequence ?argTargetClassNet. + """, + 'clause': """ + ?degreePhenomenaNet a net:Phenomena_Net ; + net:coverBaseNode ?phenomenaLeaf ; + net:targetArgumentNode ?argTargetLeaf ; + net:hasPhenomenaType amr:phenomena_degree. + ?argTargetClassNet a [rdfs:subClassOf* net:Class_Net] ; + net:coverBaseNode ?argTargetLeaf. + ?phenomenaLeaf ?argEdge ?argTargetLeaf. + ?argEdge amr:hasAmrRole amr:role_ARG6. + """, + 'binding': """ + """ +} \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/nov_transduction/technical_ctr.py b/tenet/scheme/amr_master_rule/nov_transduction/technical_ctr.py new file mode 100644 index 0000000000000000000000000000000000000000..fa396ddaccfe8be6e9719971e6fd2a26c680d938 --- /dev/null +++ b/tenet/scheme/amr_master_rule/nov_transduction/technical_ctr.py @@ -0,0 +1,80 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Net Expansion' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Net Expansion' level +#============================================================================== + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Useful technical CTR +# --------------------------------------------- + +rule_set['refine-cover-node-1'] = { + 'label': "refine-cover-node-1", + 'comment': ("Refine semantic net coverage indicators by: ", + " calculating the set of all covered nodes"), + 'construction': """ + ?net net:coverNode ?baseLeaf. + ?net net:coverNode ?argLeaf. + ?net net:coverNode ?targetLeaf. + """, + 'clause': """ + ?net a [rdfs:subClassOf* net:Net] ; + net:coverBaseNode ?baseLeaf. + OPTIONAL { ?net net:coverArgNode ?argLeaf. } + OPTIONAL { ?net net:coverTargetNode ?targetLeaf. } + """, + 'binding': """ + """ +} + +rule_set['refine-cover-node-2'] = { + 'label': "refine-cover-node-2", + 'comment': ("Refine semantic net coverage indicators by: ", + " calculating the number of covered nodes"), + 'construction': """ + ?net net:coverNodeCount ?c. + """, + 'clause': """ + SELECT ?net (COUNT(?leaf) AS ?c) + WHERE { + ?net a [rdfs:subClassOf* net:Class_Net] ; + net:coverNode ?leaf. + } + GROUP BY ?net + """, + 'binding': """ + """ +} + +# -- old --- +# rule_set['propagation-relations-to-nets'] = { +# 'label': "propagation-relations-to-nets", +# 'comment': ("Propagation relations between nodes", +# " to relations between nets"), +# 'construction': """ +# ?relationRole a net:Relation. +# ?net1 ?relationRole ?net2. +# """, +# 'clause': """ +# ?net1 a [rdfs:subClassOf* net:Net] ; +# net:coverBaseNode ?leaf1. +# ?net2 a [rdfs:subClassOf* net:Net] ; +# net:coverBaseNode ?leaf2. +# ?leaf1 ?relationEdge ?leaf2. +# ?relationEdge amr:hasAmrRole ?relationRole. +# """, +# 'binding': """ +# """ +# } +# -- --- \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/preprocessing.py b/tenet/scheme/amr_master_rule/preprocessing.py new file mode 100644 index 0000000000000000000000000000000000000000..a2f99066061daa1a9ea70cef30ab5122012061e6 --- /dev/null +++ b/tenet/scheme/amr_master_rule/preprocessing.py @@ -0,0 +1,445 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Data Preprocessing' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Data Preprocessing' level +#============================================================================== + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Preprocessing: Reclassification of concepts +# --------------------------------------------- + +rule_set['reclassify-concept-1'] = { + 'label': "reclassify-concept-1", + 'comment': "Reclassify terms concept to AMR Special concept", + 'construction': """ + ?c rdfs:subClassOf amr:AMR_Special_Concept ; + amr:hasPhenomenaLink ?phenomena. + """, + 'clause': """ + ?c a ?amrConceptClass. + VALUES ?amrConceptClass {ns3:Frame ns3:Concept ns3:NamedEntity} + ?phenomena rdfs:subClassOf* amr:AMR_Phenomena ; + amr:hasConceptLink ?phenomenaLink. + FILTER (?cLabel1 = ?phenomenaLink || + ?cLabel2 = ?phenomenaLink). + """, + 'binding':""" + BIND (strafter(str(?c), str(ns1:)) AS ?cLabel1). + BIND (strafter(str(?c), '#') AS ?cLabel2). + """ + } + + +rule_set['reclassify-concept-2'] = { + 'label': "reclassify-concept-2", + 'comment': "Reclassify terms concept to AMR Term concept", + 'construction': """ + ?c rdfs:subClassOf amr:AMR_Term_Concept. + """, + 'clause': """ + ?c a ns3:Concept. + FILTER NOT EXISTS { ?c rdfs:subClassOf amr:AMR_Special_Concept. } + FILTER ( CONTAINS(str(?c), str(ns2:)) ). + FILTER ( ?c != ns3:Frame ). + FILTER ( ?c != ns3:NamedEntity ). + """, + 'binding': '' + } + +rule_set['reclassify-concept-3'] = { + 'label': "reclassify-concept-3", + 'comment': "Reclassify core concept to AMR Relation concept", + 'construction': """ + ?c rdfs:subClassOf amr:AMR_Relation_Concept. + """, + 'clause': """ + ?c a ns3:Concept. + FILTER NOT EXISTS { ?c rdfs:subClassOf amr:AMR_Special_Concept. } + FILTER ( CONTAINS(str(?c), str(ns3:)) ). + FILTER ( ?c != ns3:Frame ). + FILTER ( ?c != ns3:NamedEntity ). + """, + 'binding': '' + } + +rule_set['reclassify-concept-4'] = { + 'label': "reclassify-concept-4", + 'comment': "Reclassify named entity to AMR Term concept", + 'construction': """ + ?c rdfs:subClassOf amr:AMR_Term_Concept. + """, + 'clause': """ + ?c a ns3:NamedEntity. + FILTER NOT EXISTS { ?c rdfs:subClassOf amr:AMR_Special_Concept. } + """, + 'binding': '' + } + +rule_set['reclassify-concept-5'] = { + 'label': "reclassify-concept-5", + 'comment': "Reclassify frame to AMR Predicat concept", + 'construction': """ + ?c rdfs:subClassOf amr:AMR_Predicat_Concept. + """, + 'clause': """ + ?c a ns3:Frame. + FILTER NOT EXISTS { ?c rdfs:subClassOf amr:AMR_Special_Concept. } + """, + 'binding': '' + } + + +# --------------------------------------------- +# Preprocessing: Reclassification of variables +# --------------------------------------------- + +rule_set['reclassify-variable'] = { + 'label': "reclassify-variable", + 'comment': "Reclassify concept instance to AMR variable", + 'construction': """ + ?v a amr:AMR_Variable. + """, + 'clause': """ + ?c rdfs:subClassOf* amr:AMR_Concept. + ?v a ?c. + """, + 'binding': '' + } + + +# --------------------------------------------- +# Preprocessing: Reclassification of roles +# --------------------------------------------- + +rule_set['reclassify-role-1'] = { + 'label': "reclassify-role-1", + 'comment': "Reclassify role to AMR core role", + 'construction': """ + ?newRole rdfs:subClassOf amr:AMR_Core_Role ; + amr:fromAmrLkFramerole ?r. + """, + 'clause': """ + ?r a ns1:FrameRole. + """, + 'binding':""" + BIND (strafter(str(?r), str(ns1:)) AS ?rLabel) + BIND (strbefore(?rLabel, '.') AS ?rolesetId) + BIND (strafter(?rLabel, '.') AS ?roleId) + BIND (CONCAT(str(amr:), 'role') AS ?n1). + BIND (CONCAT(?n1, '_', ?roleId) AS ?n2). + BIND (uri(?n2) AS ?newRole). + """ + } + +rule_set['reclassify-role-2'] = { + 'label': "reclassify-rolet-2", + 'comment': "Reclassify role to AMR non-core role", + 'construction': """ + ?newRole rdfs:subClassOf amr:AMR_NonCore_Role ; + amr:fromAmrLkRole ?r. + """, + 'clause': """ + ?r a ns3:Role. + FILTER ( ?r != ns1:FrameRole ). + FILTER NOT EXISTS { ?newRole rdfs:subClassOf* amr:AMR_Role. } + """, + 'binding':""" + BIND (strafter(str(?r), '#') AS ?rLabel) + BIND (CONCAT(str(amr:), 'role') AS ?n1). + BIND (CONCAT(?n1, '_', ?rLabel) AS ?n2). + BIND (uri(?n2) AS ?newRole). + """ + } + +rule_set['reclassify-role-3'] = { + 'label': "reclassify-rolet-3", + 'comment': "Add link with AmrLk role to AMR role", + 'construction': """ + ?newRole amr:fromAmrLkRole ?r. + """, + 'clause': """ + ?r a ns3:Role. + ?newRole rdfs:subClassOf* amr:AMR_Role. + FILTER ( ?r != ns1:FrameRole ). + """, + 'binding':""" + BIND (strafter(str(?r), '#') AS ?rLabel) + BIND (CONCAT(str(amr:), 'role') AS ?n1). + BIND (CONCAT(?n1, '_', ?rLabel) AS ?n2). + BIND (uri(?n2) AS ?newRole). + """ + } + + +# --------------------------------------------- +# Preprocessing: Addition of leafs and edges +# --------------------------------------------- + +rule_set['add-amr-leaf'] = { + 'label': "add-leaf-1", + 'comment': "Add AMR leaf corresponding to concept/variable relation", + 'construction': """ + ?newLeaf a amr:AMR_Leaf ; + amr:hasVariable ?v ; + amr:hasConcept ?c. + """, + 'clause': """ + ?c rdfs:subClassOf* amr:AMR_Concept. + ?v a ?c. + """, + 'binding':""" + BIND (strafter(str(?c), '#') AS ?cLabel1) + BIND (strafter(str(?c), str(ns1:)) AS ?cLabel2) + BIND (IF (STRLEN(?cLabel1) > 0, ?cLabel1, ?cLabel2) AS ?cLabel) + BIND (strafter(str(?v), '#') AS ?vLabel) + BIND (CONCAT(str(amr:), 'leaf') AS ?n1). + BIND (CONCAT(?n1, '_', ?cLabel) AS ?n2). + BIND (CONCAT(?n2, '_', ?vLabel) AS ?n3). + BIND (uri(?n3) AS ?newLeaf). + """ + } + + +rule_set['add-amr-edge-1'] = { + 'label': "add-amr-edge-1", + 'comment': ("Add AMR edge corresponding to a FrameRole relation", + " between two leafs"), + 'construction': """ + ?newEdge a amr:AMR_Edge ; + amr:hasRolesetID ?rolesetId ; + amr:hasRoleID ?roleId ; + amr:hasRoleTag ?roleTag. + ?leaf1 ?newEdge ?leaf2. + """, + 'clause': """ + ?r a ns1:FrameRole. + ?leaf1 amr:hasVariable ?v1. + ?leaf2 amr:hasVariable ?v2. + ?v1 ?r ?v2. + """, + 'binding':""" + BIND (strafter(str(?r), str(ns1:)) AS ?rLabel) + BIND (strbefore(?rLabel, '.') AS ?rolesetId) + BIND (strafter(?rLabel, '.') AS ?roleId) + BIND (?rLabel AS ?roleTag) + BIND (strafter(str(?v1), '#') AS ?v1Label) + BIND (strafter(str(?v2), '#') AS ?v2Label) + BIND (CONCAT(str(amr:), 'edge') AS ?n1). + BIND (CONCAT(?n1, '_', ?rLabel) AS ?n2). + BIND (CONCAT(?n2, '_', ?v1Label) AS ?n3). + BIND (CONCAT(?n3, '_', ?v2Label) AS ?n4). + BIND (uri(?n4) AS ?newEdge). + """ + } + +rule_set['add-amr-edge-2'] = { + 'label': "add-amr-edge-2", + 'comment': ("Add AMR edge corresponding to a Role relation", + " between two leafs"), + 'construction': """ + ?newEdge a amr:AMR_Edge ; + amr:hasRolesetID ?rolesetId ; + amr:hasRoleID ?roleId ; + amr:hasRoleTag ?roleTag. + ?leaf1 ?newEdge ?leaf2. + """, + 'clause': """ + ?r a ns3:Role. + ?leaf1 amr:hasVariable ?v1. + ?leaf2 amr:hasVariable ?v2. + ?v1 ?r ?v2. + """, + 'binding':""" + BIND (strafter(str(?r), '#') AS ?rLabel) + BIND (strbefore(?rLabel, '.') AS ?rolesetId) + BIND (strafter(?rLabel, '.') AS ?roleId) + BIND (?rLabel AS ?roleTag) + BIND (strafter(str(?v1), '#') AS ?v1Label) + BIND (strafter(str(?v2), '#') AS ?v2Label) + BIND (CONCAT(str(amr:), 'edge') AS ?n1). + BIND (CONCAT(?n1, '_', ?rLabel) AS ?n2). + BIND (CONCAT(?n2, '_', ?v1Label) AS ?n3). + BIND (CONCAT(?n3, '_', ?v2Label) AS ?n4). + BIND (uri(?n4) AS ?newEdge). + """ + } + + +# --------------------------------------------- +# Preprocessing: Addition of root +# --------------------------------------------- + +rule_set['add-amr-root'] = { + 'label': "add-amr-root", + 'comment': ("Add root instance in AMR_Root"), + 'construction': """ + ?newRoot a amr:AMR_Root ; + amr:hasRootLeaf ?leaf ; + amr:hasSentenceID ?graphId ; + amr:hasSentenceStatement ?graphSentence ; + amr:fromAmrLkRoot ?r. + """, + 'clause': """ + ?r a ns3:AMR. + ?r ns3:root ?lkRoot. + ?r ns3:has-id ?graphId. + ?r ns3:has-sentence ?graphSentence. + ?leaf amr:hasVariable ?lkRoot. + """, + 'binding':""" + BIND (CONCAT(str(amr:), 'root') AS ?n1). + BIND (CONCAT(?n1, '_', ?graphId) AS ?n2). + BIND (uri(?n2) AS ?newRoot). + """ + } + + +# --------------------------------------------- +# Preprocessing: Addition of values +# --------------------------------------------- + +rule_set['add-amr-value-for-name-relation'] = { + 'label': "add-value-for-name-relation", + 'comment': ("Add a value for each name relation, corresponding to ", + "variables with label in AMR Linked Data, ", + "and to the name AMR relations in AMR graphs"), + 'construction': """ + ?newValue a amr:AMR_Value ; + rdfs:label ?vLabel. + ?v amr:name ?newValue. + """, + 'clause': """ + ?v a amr:AMR_Variable. + ?v rdfs:label ?vLabel. + """, + 'binding':""" + BIND (REPLACE(?vLabel, ' ', "") AS ?vRef). + BIND (CONCAT(str(amr:), 'value') AS ?n1). + BIND (CONCAT(?n1, '_', ?vRef) AS ?n2). + BIND (uri(?n2) AS ?newValue). + """ + } + +rule_set['add-amr-value-for-quant-relation'] = { + 'label': "add-value-for-quant-relation", + 'comment': ("Add a value for each quant relation, corresponding to ", + "variables with quant Property in AMR Linked Data, ", + "and to the quant AMR relations in AMR graphs"), + 'construction': """ + ?newValue a amr:AMR_Value ; + rdfs:label ?vQuant. + ?v amr:quant ?newValue. + """, + 'clause': """ + ?v a amr:AMR_Variable. + ?v ns2:quant ?vQuant. + """, + 'binding':""" + BIND (REPLACE(?vQuant, ' ', "") AS ?vRef). + BIND (CONCAT(str(amr:), 'value') AS ?n1). + BIND (CONCAT(?n1, '_', ?vRef) AS ?n2). + BIND (uri(?n2) AS ?newValue). + """ + } + + +# --------------------------------------------- +# Preprocessing: Set labels for concepts, variables and roles +# --------------------------------------------- + +rule_set['set-amr-label-for-concepts'] = { + 'label': "set-amr label-for-concepts", + 'comment': "Set AMR label for all concepts", + 'construction': """ + ?c amr:label ?cLabel. + """, + 'clause': """ + ?c rdfs:subClassOf* amr:AMR_Concept. + """, + 'binding':""" + BIND (strafter(str(?c), '#') AS ?cLabel1) + BIND (strafter(str(?c), str(ns1:)) AS ?cLabel2) + BIND (IF (STRLEN(?cLabel1) > 0, ?cLabel1, ?cLabel2) AS ?cLabel) + """ + } + +rule_set['set-amr-label-for-variables'] = { + 'label': "set-amr-label-for-variables", + 'comment': "Set AMR label for all variables", + 'construction': """ + ?v amr:label ?vLabel. + """, + 'clause': """ + ?v a amr:AMR_Variable. + """, + 'binding':""" + BIND (strafter(str(?v), '#') AS ?vLabel) + """ + } + +rule_set['set-amr-label-for-roles'] = { + 'label': "set-amr-label-for-variables", + 'comment': "Set AMR label for all variables", + 'construction': """ + ?r amr:label ?rLabel. + """, + 'clause': """ + ?r rdfs:subClassOf* amr:AMR_Role. + """, + 'binding':""" + BIND (strafter(str(?r), 'role_') AS ?rLabel) + """ + } + + +# --------------------------------------------- +# Preprocessing: Update leafs and edges +# --------------------------------------------- + +rule_set['update-amr-edge-role-1'] = { + 'label': "update-amr-edge-role-1", + 'comment': ("Update AMR edge by adding relation with AMR_Role", + "(using comparison between label and role id)"), + 'construction': """ + ?edge amr:hasAmrRole ?role. + """, + 'clause': """ + ?edge a amr:AMR_Edge ; + amr:hasRoleID ?edgeRoleId. + ?role rdfs:subClassOf* amr:AMR_Role ; + amr:label ?roleLabel. + FILTER ( ?roleLabel != '' ). + FILTER ( ?edgeRoleId = ?roleLabel ). + """, + 'binding': '' + } + +rule_set['update-amr-edge-role-2'] = { + 'label': "update-amr-edge-role-2", + 'comment': ("Update AMR edge by adding relation with AMR_Role", + "(using comparison between label and role tag)"), + 'construction': """ + ?edge amr:hasAmrRole ?role. + """, + 'clause': """ + ?edge a amr:AMR_Edge ; + amr:hasRoleTag ?edgeRoleId. + ?role rdfs:subClassOf* amr:AMR_Role ; + amr:label ?roleLabel. + FILTER ( ?roleLabel != '' ). + FILTER ( ?edgeRoleId = ?roleLabel ). + """, + 'binding': '' + } + diff --git a/tenet/scheme/amr_master_rule/preprocessing/__init__.py b/tenet/scheme/amr_master_rule/preprocessing/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..8d1c8b69c3fce7bea45c73efd06983e3c419a92f --- /dev/null +++ b/tenet/scheme/amr_master_rule/preprocessing/__init__.py @@ -0,0 +1 @@ + diff --git a/tenet/scheme/amr_master_rule/preprocessing/amr_reification.py b/tenet/scheme/amr_master_rule/preprocessing/amr_reification.py new file mode 100644 index 0000000000000000000000000000000000000000..94a2bd9bc031dfd6b1d636c634023326b765e305 --- /dev/null +++ b/tenet/scheme/amr_master_rule/preprocessing/amr_reification.py @@ -0,0 +1,934 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Data Preprocessing' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rules (CTR) for the analysis of +# AMR structures, at 'Data Preprocessing' level +#============================================================================== + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Reclassification of concepts +# --------------------------------------------- + +rule_set['reclassify-concept-1'] = { + 'label': "reclassify-concept-1", + 'comment': ("Reclassify LK concept to AMR Relation concept for concept: ", + " (1) corresponding to a LK term, frame or named entity,", + " (2) corresponding to an AMR phenomena/relation."), + 'construction': """ + # -- New concept + ?newConcept rdfs:subClassOf amr:AMR_Relation_Concept ; + amr:label ?cLabel ; + amr:hasPhenomenaLink ?phenomena ; + amr:fromAmrLk ?c. + + # -- Classification of the original concept as LinkedData (for tracing) + ?c rdfs:subClassOf amr:AMR_Linked_Data. + """, + 'clause': """ + # -- Identify LK concept + ?c a ?amrConceptClass. + VALUES ?amrConceptClass {ns3:Frame ns3:Concept ns3:NamedEntity} + + # -- Identify phenomena matching + ?phenomena rdfs:subClassOf* amr:AMR_Phenomena ; + amr:hasConceptLink ?phenomenaLink. + BIND (strafter(str(?c), str(ns1:)) AS ?cLabel1). + BIND (strafter(str(?c), '#') AS ?cLabel2). + FILTER (?cLabel1 = ?phenomenaLink || ?cLabel2 = ?phenomenaLink). + + # -- Filter bugs + FILTER NOT EXISTS { ?c rdfs:comment 'bug'. } + """, + 'binding':""" + # -- Label + # -- already bound --- BIND (strafter(str(?c), '#') AS ?cLabel1) + # -- already bound --- BIND (strafter(str(?c), str(ns1:)) AS ?cLabel2) + BIND (IF (STRLEN(?cLabel1) > 0, ?cLabel1, ?cLabel2) AS ?cLabel) + + # -- New concept + BIND (CONCAT(str(amr:), 'concept') AS ?n1). + BIND (CONCAT(?n1, '_', ?cLabel) AS ?n2). + BIND (uri(?n2) AS ?newConcept). + """ + } + + +rule_set['reclassify-concept-2'] = { + 'label': "reclassify-concept-2", + 'comment': ("Reclassify LK concept to AMR Predicat concept for concept: ", + " (1) corresponding to a predicat (ns3 concept),", + " (2) not corresponding to a phenomena."), + 'construction': """ + # -- New concept + ?newConcept rdfs:subClassOf amr:AMR_Predicat_Concept ; + amr:label ?cLabel ; + amr:fromAmrLk ?c. + + # -- Classification of the original concept as LinkedData (for tracing) + ?c rdfs:subClassOf amr:AMR_Linked_Data. + """, + 'clause': """ + # -- Identify LK relation concepts (ns3) + ?c a ns3:Concept. + FILTER ( CONTAINS(str(?c), str(ns3:)) ). + FILTER ( ?c != ns3:Frame ). + FILTER ( ?c != ns3:NamedEntity ). + + # -- Filter phenomena/relation + FILTER NOT EXISTS {?amrC rdfs:subClassOf amr:AMR_Relation_Concept ; + amr:fromAmrLk ?c.} + + # -- Filter bugs + FILTER NOT EXISTS { ?c rdfs:comment 'bug'. } + """, + 'binding': """ + # -- Label + BIND (strafter(str(?c), '#') AS ?cLabel1) + BIND (strafter(str(?c), str(ns1:)) AS ?cLabel2) + BIND (IF (STRLEN(?cLabel1) > 0, ?cLabel1, ?cLabel2) AS ?cLabel) + + # -- New concept + BIND (CONCAT(str(amr:), 'concept') AS ?n1). + BIND (CONCAT(?n1, '_', ?cLabel) AS ?n2). + BIND (uri(?n2) AS ?newConcept). + """ + } + + +rule_set['reclassify-concept-3'] = { + 'label': "reclassify-concept-3", + 'comment': ("Reclassify LK concept to AMR Predicat concept for concept: ", + " (1) corresponding to a frame,", + " (2) not corresponding to a relation."), + 'construction': """ + # -- New concept + ?newConcept rdfs:subClassOf amr:AMR_Predicat_Concept ; + amr:label ?cLabel ; + amr:fromAmrLk ?c. + + # -- Classification of the original concept as LinkedData (for tracing) + ?c rdfs:subClassOf amr:AMR_Linked_Data. + """, + 'clause': """ + # -- Identify LK frame concepts + ?c a ns3:Frame. + + # -- Filter phenomena/relation + FILTER NOT EXISTS {?amrC rdfs:subClassOf amr:AMR_Relation_Concept ; + amr:fromAmrLk ?c.} + + # -- Filter bugs + FILTER NOT EXISTS { ?c rdfs:comment 'bug'. } + """, + 'binding': """ + # -- Label + BIND (strafter(str(?c), '#') AS ?cLabel1) + BIND (strafter(str(?c), str(ns1:)) AS ?cLabel2) + BIND (IF (STRLEN(?cLabel1) > 0, ?cLabel1, ?cLabel2) AS ?cLabel) + + # -- New concept + BIND (CONCAT(str(amr:), 'concept') AS ?n1). + BIND (CONCAT(?n1, '_', ?cLabel) AS ?n2). + BIND (uri(?n2) AS ?newConcept). + """ + } + + +rule_set['reclassify-concept-4'] = { + 'label': "reclassify-concept-4", + 'comment': ("Reclassify LK concept to AMR Term concept for concept: ", + " (1) corresponding to a term (ns2 concept),", + " (2) not corresponding to a phenomena."), + 'construction': """ + # -- New concept + ?newConcept rdfs:subClassOf amr:AMR_Term_Concept ; + amr:label ?cLabel ; + amr:fromAmrLk ?c. + + # -- Classification of the original concept as LinkedData (for tracing) + ?c rdfs:subClassOf amr:AMR_Linked_Data. + """, + 'clause': """ + # -- Identify LK term concepts + ?c a ns3:Concept. + FILTER ( CONTAINS(str(?c), str(ns2:)) ). + FILTER ( ?c != ns3:Frame ). + FILTER ( ?c != ns3:NamedEntity ). + + # -- Filter phenomena/relation + FILTER NOT EXISTS {?amrC rdfs:subClassOf amr:AMR_Relation_Concept ; + amr:fromAmrLk ?c.} + + # -- Filter bugs + FILTER NOT EXISTS { ?c rdfs:comment 'bug'. } + """, + 'binding': """ + # -- Label + BIND (strafter(str(?c), '#') AS ?cLabel1) + BIND (strafter(str(?c), str(ns1:)) AS ?cLabel2) + BIND (IF (STRLEN(?cLabel1) > 0, ?cLabel1, ?cLabel2) AS ?cLabel) + + # -- New concept + BIND (CONCAT(str(amr:), 'concept') AS ?n1). + BIND (CONCAT(?n1, '_', ?cLabel) AS ?n2). + BIND (uri(?n2) AS ?newConcept). + """ + } + + +rule_set['reclassify-concept-5'] = { + 'label': "reclassify-concept-5", + 'comment': ("Reclassify LK concept to AMR Term concept for concept: ", + " (1) corresponding to a named entity,", + " (2) not corresponding to a relation."), + 'construction': """ + # -- New concept + ?newConcept rdfs:subClassOf amr:AMR_Term_Concept ; + amr:label ?cLabel ; + amr:fromAmrLk ?c. + + # -- Classification of the original concept as LinkedData (for tracing) + ?c rdfs:subClassOf amr:AMR_Linked_Data. + """, + 'clause': """ + # -- Identify LK named entity concepts + ?c a ns3:NamedEntity. + + # -- Filter phenomena/relation + FILTER NOT EXISTS {?amrC rdfs:subClassOf amr:AMR_Relation_Concept ; + amr:fromAmrLk ?c.} + + # -- Filter bugs + FILTER NOT EXISTS { ?c rdfs:comment 'bug'. } + """, + 'binding': """ + # -- Label + BIND (strafter(str(?c), '#') AS ?cLabel1) + BIND (strafter(str(?c), str(ns1:)) AS ?cLabel2) + BIND (IF (STRLEN(?cLabel1) > 0, ?cLabel1, ?cLabel2) AS ?cLabel) + + # -- New concept + BIND (CONCAT(str(amr:), 'concept') AS ?n1). + BIND (CONCAT(?n1, '_', ?cLabel) AS ?n2). + BIND (uri(?n2) AS ?newConcept). + """ + } + + +# --------------------------------------------- +# Reclassification of roles *** OLD *** +# --------------------------------------------- + +# rule_set['reclassify-role-1'] = { +# 'label': "reclassify-role-1", +# 'comment': "Reclassify role to AMR core role", +# 'construction': """ +# # -- New AMR core role +# ?newRole rdfs:subClassOf amr:AMR_Core_Role ; +# amr:label ?roleId ; +# amr:fromAmrLk ?r. +# """, +# 'clause': """ +# # -- Identify core role +# ?r a ns1:FrameRole. +# """, +# 'binding':""" +# # -- Label +# BIND (strafter(str(?r), '#') AS ?rLabel1) +# BIND (strafter(str(?r), str(ns1:)) AS ?rLabel2) +# BIND (IF (STRLEN(?rLabel1) > 0, ?rLabel1, ?rLabel2) AS ?rLabel) + +# # -- Id +# BIND (strbefore(?rLabel, '.') AS ?rolesetId) +# BIND (strafter(?rLabel, '.') AS ?roleId) + +# # -- New role +# BIND (CONCAT(str(amr:), 'role') AS ?n1). +# BIND (CONCAT(?n1, '_', ?roleId) AS ?n2). +# BIND (uri(?n2) AS ?newRole). +# """ +# } + +# rule_set['reclassify-role-2'] = { +# 'label': "reclassify-rolet-2", +# 'comment': "Reclassify role to AMR non-core role", +# 'construction': """ +# # -- New AMR non core role +# ?newRole rdfs:subClassOf amr:AMR_NonCore_Role ; +# amr:label ?rLabel ; +# amr:fromAmrLk ?r. +# """, +# 'clause': """ +# # -- Identify non core role +# ?r a ns3:Role. +# FILTER ( ?r != ns1:FrameRole ). + +# # -- Filter core role +# FILTER NOT EXISTS {?newRole rdfs:subClassOf* amr:AMR_Role ; +# amr:fromAmrLk ?r.} +# """, +# 'binding':""" +# # -- Label +# BIND (strafter(str(?r), '#') AS ?rLabel1) +# BIND (strafter(str(?r), str(ns1:)) AS ?rLabel2) +# BIND (IF (STRLEN(?rLabel1) > 0, ?rLabel1, ?rLabel2) AS ?rLabel) + +# # -- New role +# BIND (CONCAT(str(amr:), 'role') AS ?n1). +# BIND (CONCAT(?n1, '_', ?rLabel) AS ?n2). +# BIND (uri(?n2) AS ?newRole). +# """ +# } + + +# --------------------------------------------- +# Set labels for variables and roles +# --------------------------------------------- + +# rule_set['set-amr-label-for-variables'] = { +# 'label': "set-amr-label-for-variables", +# 'comment': "Set AMR label for all variables", +# 'construction': """ +# ?v amr:label ?vLabel. +# """, +# 'clause': """ +# ?v a amr:AMR_Variable. +# """, +# 'binding':""" +# BIND (strafter(str(?v), '#') AS ?vLabel) +# """ +# } + +# rule_set['set-amr-label-for-roles'] = { +# 'label': "set-amr-label-for-variables", +# 'comment': "Set AMR label for all variables", +# 'construction': """ +# ?r amr:label ?rLabel. +# """, +# 'clause': """ +# ?r rdfs:subClassOf* amr:AMR_Role. +# """, +# 'binding':""" +# BIND (strafter(str(?r), 'role_') AS ?rLabel) +# """ +# } + + +# --------------------------------------------- +# Reification of some roles as first-class concept +# --------------------------------------------- + +rule_set['reify-roles-as-concept'] = { + 'label': "reify-roles-as-concept", + 'comment': ("reify some LK roles to AMR Relation concept for: ", + " (1) AMR relation with reification,", + " (2) non core LK role ", + " (3) matching between role and reification relation."), + 'construction': """ + # -- New concept + ?newConcept rdfs:subClassOf amr:AMR_Predicat_Concept ; + amr:isReifiedConcept true ; + amr:label ?reificationConcept ; + amr:fromAmrLk ?r. + + # -- Classification of the original concept as LinkedData (for tracing) + ?r rdfs:subClassOf amr:AMR_Linked_Data. + """, + 'clause': """ + # -- Identify AMR relation with reification + ?reifiableRelation rdfs:subClassOf amr:AMR_Relation ; + amr:hasReification true ; + amr:hasRelationName ?relationName ; + amr:hasReificationConcept ?reificationConcept. + # -- old --- amr:hasReificationDomain ?reificationDomain ; + # -- old --- amr:hasReificationRange ?reificationRange. + + # -- Identify non core role + ?r a ns3:Role. + FILTER ( ?r != ns1:FrameRole ). + + # -- Identify role and reification relation matching + BIND (strafter(str(?r), str(ns1:)) AS ?rLabel1). + BIND (strafter(str(?r), '#') AS ?rLabel2). + FILTER (?rLabel1 = ?relationName || ?rLabel2 = ?relationName). + """, + 'binding': """ + # -- New concept + BIND (CONCAT(str(amr:), 'concept') AS ?n1). + BIND (CONCAT(?n1, '_', ?relationName) AS ?n2). + BIND (uri(?n2) AS ?newConcept). + """ + } + + +# --------------------------------------------- +# Reclassification of variables +# --------------------------------------------- + +rule_set['reclassify-existing-variable'] = { + 'label': "reclassify-existing-variable", + 'comment': "Reclassify existing LK variable to AMR variable", + 'construction': """ + # -- New variable + ?newVariable a amr:AMR_Variable ; + amr:label ?vLabel ; + amr:fromAmrLk ?v. + + # -- Name relation + ?newVariable amr:name ?vName. + + # -- Classification of the original concept as LinkedData (for tracing) + ?v rdfs:subClassOf amr:AMR_Linked_Data. + """, + 'clause': """ + # -- Identify variable + ?c rdfs:subClassOf* amr:AMR_Concept ; + amr:fromAmrLk ?linkedC. + ?v a ?linkedC. + + # -- Identify rdfs:label (corresponding to name relation) + OPTIONAL {?v rdfs:label ?vName} + """, + 'binding': """ + # -- New label + BIND (strafter(str(?v), '#') AS ?vLabel) + + # -- New variable + BIND (CONCAT(str(amr:), 'variable') AS ?n1). + BIND (CONCAT(?n1, '_', ?vLabel) AS ?n2). + BIND (uri(?n2) AS ?newVariable). + """ + } + + +rule_set['add-new-variable-for-reified-concept'] = { + 'label': "add-new-variable-for-reified-concept", + 'comment': "Add new variable for reified concept", + 'construction': """ + # -- New variable + ?newVariable a amr:AMR_Variable ; + amr:isReifiedVariable true ; + amr:label ?vLabel. + + # -- Linking new variable to LK role (for tracing) + ?newVariable a ?r. + """, + 'clause': """ + # -- Identify reified concept + ?reifiedConcept rdfs:subClassOf amr:AMR_Predicat_Concept ; + amr:isReifiedConcept true ; + amr:label ?cLabel ; + amr:fromAmrLk ?r. + # -- old --- ?vIn ?r ?vOut. + """, + 'binding': """# -- New label + BIND (strafter(str(?r), '#') AS ?rLabel1) + BIND (strafter(str(?r), str(ns1:)) AS ?rLabel2) + BIND (IF (STRLEN(?rLabel1) > 0, ?rLabel1, ?rLabel2) AS ?rLabel) + BIND (SUBSTR(?rLabel, 1, 1) AS ?vLetter) + BIND (CONCAT(?vLetter, '9') AS ?vLabel). + + # -- old --- + # -- old --- BIND (strafter(str(?vIn), '#') AS ?vl1). + # -- old --- BIND (CONCAT(?vl1, ?vLetter) AS ?vl2). + # -- old --- BIND (CONCAT(?vl2, strafter(str(?vOut), '#')) AS ?vl3). + + # -- New variable + BIND (CONCAT(str(amr:), 'variable') AS ?n1). + BIND (CONCAT(?n1, '_', ?vLabel) AS ?n2). + BIND (uri(?n2) AS ?newVariable). + """ + } + + +# --------------------------------------------- +# Addition of leafs +# --------------------------------------------- + +rule_set['add-amr-leaf-for-reclassified-concept'] = { + 'label': "add-amr-leaf-for-reclassified-concept", + 'comment': "Add AMR leaf corresponding to concept/variable relation", + 'construction': """ + # -- New leaf + ?newLeaf a amr:AMR_Leaf ; + amr:hasVariable ?newV ; + amr:hasConcept ?c. + """, + 'clause': """ + # -- Identify concept + ?c rdfs:subClassOf* amr:AMR_Concept ; + amr:label ?cLabel ; + amr:fromAmrLk ?linkedC. + + # -- Identify new variable + ?newV a amr:AMR_Variable ; + amr:label ?vLabel ; + amr:fromAmrLk ?v. + + # -- identify matching between concept and (LK) variable + ?v a ?linkedC. + """, + 'binding':""" + # -- New labels + # -- old --- BIND (strafter(str(?linkedC), '#') AS ?cLabel1) + # -- old --- BIND (strafter(str(?linkedC), str(ns1:)) AS ?cLabel2) + # -- old --- BIND (IF (STRLEN(?cLabel1) > 0, ?cLabel1, ?cLabel2) AS ?cLabel) + # -- old --- BIND (strafter(str(?v), '#') AS ?vLabel) + + # -- New leaf + BIND (CONCAT(str(amr:), 'leaf') AS ?n1). + BIND (CONCAT(?n1, '_', ?cLabel) AS ?n2). + BIND (CONCAT(?n2, '_', ?vLabel) AS ?n3). + BIND (uri(?n3) AS ?newLeaf). + """ + } + + +rule_set['add-amr-leaf-for-reified-concept'] = { + 'label': "add-amr-leaf-for-reified-concept", + 'comment': "Add AMR leaf corresponding to reified concept (with new variable)", + 'construction': """ + # -- New leaf + ?newLeaf a amr:AMR_Leaf ; + amr:isReifiedLeaf true ; + amr:hasVariable ?v ; + amr:hasConcept ?c. + """, + 'clause': """ + # -- Identify reified concept + ?c rdfs:subClassOf* amr:AMR_Concept ; + amr:isReifiedConcept true ; + amr:label ?cLabel ; + amr:fromAmrLk ?linkedC. + + # -- Identify reified variable + ?v a amr:AMR_Variable ; + amr:isReifiedVariable true ; + amr:label ?vLabel. + + # -- Identify matching between reified concept and variable + ?v a ?linkedC. + """, + 'binding':""" + # -- New labels + # -- old --- BIND (strafter(str(?linkedC), '#') AS ?cLabel1) + # -- old --- BIND (strafter(str(?linkedC), str(ns1:)) AS ?cLabel2) + # -- old --- BIND (IF (STRLEN(?cLabel1) > 0, ?cLabel1, ?cLabel2) AS ?cLabel) + # -- old --- BIND (strafter(str(?v), '#') AS ?vLabel) + + # -- New leaf + BIND (CONCAT(str(amr:), 'leaf') AS ?n1). + BIND (CONCAT(?n1, '_', ?cLabel) AS ?n2). + BIND (CONCAT(?n2, '_', ?vLabel) AS ?n3). + BIND (uri(?n3) AS ?newLeaf). + """ + } + + +# --------------------------------------------- +# Addition of edges +# --------------------------------------------- + +rule_set['add-amr-edge-for-core-relation'] = { + 'label': "add-amr-edge-for-core-relation", + 'comment': ("Add AMR edge corresponding to: ", + " (x) LK core relation between two leafs"), + 'construction': """ + # -- New edge + ?newEdge a amr:AMR_Edge ; + amr:hasRoleID ?roleId. + # -- old --- amr:hasRolesetID ?rolesetId ; + # -- old --- amr:hasRoleID ?roleId ; + # -- old --- amr:hasRoleTag ?roleTag. + + # -- New relation between leafs + ?leaf1 ?newEdge ?leaf2. + """, + 'clause': """ + # -- Identify LK relation + ?r a ?amrLkRelation. + VALUES ?amrLkRelation {ns1:FrameRole ns3:Role} + + # -- Filter reified role + FILTER NOT EXISTS { + ?newConcept rdfs:subClassOf amr:AMR_Predicat_Concept ; + amr:isReifiedConcept true ; + amr:fromAmrLk ?r. + } + + # -- identify leafs and variables + ?leaf1 amr:hasVariable ?v1. + ?leaf2 amr:hasVariable ?v2. + ?v1 a amr:AMR_Variable ; + amr:label ?v1Label ; + amr:fromAmrLk ?v1Link. + ?v2 a amr:AMR_Variable ; + amr:label ?v2Label ; + amr:fromAmrLk ?v2Link. + + # -- Identify matching + ?v1Link ?r ?v2Link. + """, + 'binding':""" + # -- New labels + BIND (strafter(str(?r), '#') AS ?rLabel1) + BIND (strafter(str(?r), str(ns1:)) AS ?rLabel2) + BIND (IF (STRLEN(?rLabel1) > 0, ?rLabel1, ?rLabel2) AS ?rLabel) + BIND (IF (CONTAINS(?rLabel, "."), + strafter(?rLabel, '.'), + ?rLabel) AS ?roleId) + # -- old --- BIND (IF (STRLEN(?rLabel1) > 0, ?rLabel1, ?rLabel2) AS ?rLabel3) + # -- old --- BIND (IF (CONTAINS(?rLabel3, "."), ?rLabel3, CONCAT("amr.", ?rLabel3)) AS ?roleTag) + # -- old --- BIND (strbefore(?roleTag, '.') AS ?rolesetId) + # -- old --- BIND (strafter(?roleTag, '.') AS ?roleId) + # -- old --- BIND (IF (STRLEN(?roleId) > 0, ?roleId, ?rLabel3) AS ?rLabel) + + # -- New edge + BIND (CONCAT(str(amr:), 'edge') AS ?n1). + BIND (CONCAT(?n1, '_', ?v1Label) AS ?n2). + BIND (CONCAT(?n2, '_', ?roleId) AS ?n3). + BIND (CONCAT(?n3, '_', ?v2Label) AS ?n4). + BIND (uri(?n4) AS ?newEdge). + """ + } + +rule_set['add-amr-edge-for-reified-concept'] = { + 'label': "add-amr-edge-for-reified-concept", + 'comment': ("Add AMR edge corresponding to: ", + " (x) reification of LK non-core relation to concept"), + 'construction': """ + # -- New edge (ARG0) + ?newEdge0 a amr:AMR_Edge ; + amr:hasRoleID ?roleId0. + # -- old --- amr:hasRolesetID ?rolesetId0 ; + # -- old --- amr:hasRoleID ?roleId0 ; + # -- old --- amr:hasRoleTag ?roleTag0. + + # -- New edge (ARG1) + ?newEdge1 a amr:AMR_Edge ; + amr:hasRoleID ?roleId1. + # -- old --- amr:hasRolesetID ?rolesetId1 ; + # -- old --- amr:hasRoleID ?roleId1 ; + # -- old --- amr:hasRoleTag ?roleTag1. + + # -- New relations between leafs + ?reifiedLeaf ?newEdge0 ?leaf1. + ?reifiedLeaf ?newEdge1 ?leaf2. + """, + 'clause': """ + # -- Identify reified leaf + ?reifiedLeaf a amr:AMR_Leaf ; + amr:isReifiedLeaf true ; + amr:hasVariable ?reifiedVariable ; + amr:hasConcept ?reifiedConcept. + ?reifiedVariable amr:label ?rvLabel. + + # -- Identify LK relation corresponding to the reified concept + ?reifiedConcept amr:fromAmrLk ?r. + + # -- Identify leafs and variables + ?leaf1 amr:hasVariable ?v1. + ?leaf2 amr:hasVariable ?v2. + ?v1 a amr:AMR_Variable ; + amr:label ?v1Label ; + amr:fromAmrLk ?v1Link. + ?v2 a amr:AMR_Variable ; + amr:label ?v2Label ; + amr:fromAmrLk ?v2Link. + + # -- Identify matching + ?v1Link ?r ?v2Link. + """, + 'binding':""" + # -- New labels + # -- old --- BIND (strafter(str(?r), '#') AS ?rLabel1) + # -- old --- BIND (strafter(str(?r), str(ns1:)) AS ?rLabel2) + # -- old --- BIND (IF (STRLEN(?rLabel1) > 0, ?rLabel1, ?rLabel2) AS ?rLabel3) + # -- old --- BIND (IF (CONTAINS(?rLabel3, "."), + # -- old --- ?rLabel3, + # -- old --- CONCAT("amr.", ?rLabel3)) AS ?roleTag) + # -- old --- BIND (strbefore(?roleTag, '.') AS ?rolesetId) + # -- old --- BIND (strafter(?roleTag, '.') AS ?roleId) + # -- old --- BIND (IF (STRLEN(?roleId) > 0, ?roleId, ?rLabel3) AS ?rLabel) + + # -- New labels for ARG0 edge + # -- old --- BIND ("amr.ARG0" AS ?roleTag0) + # -- old --- BIND (strbefore(?roleTag0, '.') AS ?rolesetId0) + # -- old --- BIND (strafter(?roleTag0, '.') AS ?roleId0) + + # -- New labels for ARG1 edge + # -- old --- BIND ("amr.ARG1" AS ?roleTag1) + # -- old --- BIND (strbefore(?roleTag1, '.') AS ?rolesetId1) + # -- old --- BIND (strafter(?roleTag1, '.') AS ?roleId1) + + # -- New labels + BIND ("ARG0" AS ?roleId0) + BIND ("ARG1" AS ?roleId1) + + # -- New edge (ARG0) + BIND (CONCAT(str(amr:), 'edge') AS ?n01). + BIND (CONCAT(?n01, '_', ?rvLabel) AS ?n02). + BIND (CONCAT(?n02, '_', ?roleId0) AS ?n03). + BIND (CONCAT(?n03, '_', ?v1Label) AS ?n04). + BIND (uri(?n04) AS ?newEdge0). + + # -- New edge (ARG1) + BIND (CONCAT(str(amr:), 'edge') AS ?n11). + BIND (CONCAT(?n11, '_', ?rvLabel) AS ?n12). + BIND (CONCAT(?n12, '_', ?roleId1) AS ?n13). + BIND (CONCAT(?n13, '_', ?v2Label) AS ?n14). + BIND (uri(?n14) AS ?newEdge1). + """ + } + +rule_set['add-amr-edge-for-name-relation'] = { + 'label': "add-amr-edge-for-name-relation", + 'comment': ("Add AMR edge corresponding to: ", + " (x) leaf with name relation."), + 'construction': """ + # -- New value + ?newValue a amr:AMR_Value ; + rdfs:label ?vName. + + # -- New edge + ?newEdge a amr:AMR_Edge ; + amr:hasRoleID ?roleId. + # -- old --- amr:hasRolesetID ?rolesetId ; + # -- old --- amr:hasRoleID ?roleId ; + # -- old --- amr:hasRoleTag ?roleTag. + + # -- New relation between leaf and value + ?leaf ?newEdge ?newValue. + """, + 'clause': """ + # -- Identify leaf with name relation + ?leaf a amr:AMR_Leaf ; + amr:hasVariable ?v ; + amr:hasConcept ?c. + ?v a amr:AMR_Variable ; + amr:label ?vLabel ; + amr:name ?vName. + """, + 'binding':""" + # -- New value + BIND (REPLACE(?vName, ' ', "") AS ?nvLabel). + BIND (CONCAT(str(amr:), 'value') AS ?nv1). + BIND (CONCAT(?nv1, '_', ?nvLabel) AS ?nv2). + BIND (uri(?nv2) AS ?newValue). + + # -- New labels + BIND ('amr.name' AS ?rLabel). + BIND (strbefore(?rLabel, '.') AS ?rolesetId). + BIND (strafter(?rLabel, '.') AS ?roleId). + BIND (?rLabel AS ?roleTag). + # -- old --- BIND (strafter(str(?v), '#') AS ?vLabel). + + # -- New edge + BIND (CONCAT(str(amr:), 'edge') AS ?ne1). + BIND (CONCAT(?ne1, '_', ?vLabel) AS ?ne2). + BIND (CONCAT(?ne2, '_', ?roleId) AS ?ne3). + BIND (CONCAT(?ne3, '_', ?nvLabel) AS ?ne4). + BIND (uri(?ne4) AS ?newEdge). + """ + } + + +rule_set['add-amr-edge-for-quant-relation'] = { + 'label': "add-value-for-quant-relation", + 'comment': ("Add AMR edge corresponding to: ", + " (x) leaf with quant relation."), + 'construction': """ + # -- New value + ?newValue a amr:AMR_Value ; + rdfs:label ?vLabel. + + # -- New edge + ?newEdge a amr:AMR_Edge ; + amr:hasRoleID ?roleId. + # -- old --- amr:hasRolesetID ?rolesetId ; + # -- old --- amr:hasRoleID ?roleId ; + # -- old --- amr:hasRoleTag ?roleTag. + + # -- New relation between leaf and value + ?leaf ?newEdge ?newValue. + """, + 'clause': """ + # -- Identify leaf + ?leaf a amr:AMR_Leaf ; + amr:hasVariable ?v ; + amr:hasConcept ?c. + ?v a amr:AMR_Variable ; + amr:label ?vLabel ; + amr:fromAmrLk ?vLink. + + # -- Identify matching with quant relation (ns2:quant) + ?vLink ns2:quant ?vQuant. + """, + 'binding':""" + # -- New label + BIND (REPLACE(?vQuant, ' ', "") AS ?nvLabel). + + # -- New value + BIND (CONCAT(str(amr:), 'value') AS ?nv1). + BIND (CONCAT(?nv1, '_', ?nvLabel) AS ?nv2). + BIND (uri(?nv2) AS ?newValue). + + # -- New labels + BIND ('amr.quant' AS ?rLabel). + BIND (strbefore(?rLabel, '.') AS ?rolesetId). + BIND (strafter(?rLabel, '.') AS ?roleId). + BIND (?rLabel AS ?roleTag). + # -- old --- BIND (strafter(str(?v), '#') AS ?vLabel). + + # -- New edge + BIND (CONCAT(str(amr:), 'edge') AS ?ne1). + BIND (CONCAT(?ne1, '_', ?vLabel) AS ?ne2). + BIND (CONCAT(?ne2, '_', ?roleId) AS ?ne3). + BIND (CONCAT(?ne3, '_', ?nvLabel) AS ?ne4). + BIND (uri(?ne4) AS ?newEdge). + """ + } + + +rule_set['add-amr-edge-for-polarity-relation'] = { + 'label': "add-amr-edge-for-polarity-relation", + 'comment': ("Add AMR edge corresponding to: ", + " (x) leaf with polarity relation."), + 'construction': """ + # -- New value + ?newValue a amr:AMR_Value ; + rdfs:label ?nvLabel. + + # -- New edge + ?newEdge a amr:AMR_Edge ; + amr:hasRoleID ?roleId. + # -- old --- amr:hasRolesetID ?rolesetId ; + # -- old --- amr:hasRoleID ?roleId ; + # -- old --- amr:hasRoleTag ?roleTag. + + # -- New relation between leaf and value + ?leaf ?newEdge ?newValue. + """, + 'clause': """ + # -- Identify leaf + ?leaf a amr:AMR_Leaf ; + amr:hasVariable ?v ; + amr:hasConcept ?c. + ?v a amr:AMR_Variable ; + amr:label ?vLabel ; + amr:fromAmrLk ?vLink. + + # -- Identify matching with polarity relation (ns2:polarity) + ?vLink ns2:polarity ?vPolarity. + """, + 'binding':""" + # -- New label + BIND (REPLACE(?vPolarity, ' ', "") AS ?nvl1). + BIND (REPLACE(?nvl1, '-', 'negative') AS ?nvLabel). + + # -- New value + BIND (CONCAT(str(amr:), 'value') AS ?nv1). + BIND (CONCAT(?nv1, '_', ?nvLabel) AS ?nv2). + BIND (uri(?nv2) AS ?newValue). + + # -- New labels + BIND ('amr.polarity' AS ?rLabel). + BIND (strbefore(?rLabel, '.') AS ?rolesetId). + BIND (strafter(?rLabel, '.') AS ?roleId). + BIND (?rLabel AS ?roleTag). + # -- old --- BIND (strafter(str(?v), '#') AS ?vLabel). + + # -- New edge + BIND (CONCAT(str(amr:), 'edge') AS ?ne1). + BIND (CONCAT(?ne1, '_', ?vLabel) AS ?ne2). + BIND (CONCAT(?ne2, '_', ?roleId) AS ?ne3). + BIND (CONCAT(?ne3, '_', ?nvLabel) AS ?ne4). + BIND (uri(?ne4) AS ?newEdge). + """ + } + + +# --------------------------------------------- +# Update leafs and edges *** TODO *** +# --------------------------------------------- + +rule_set['update-amr-edge-role-1'] = { + 'label': "update-amr-edge-role-1", + 'comment': ("Update AMR edge by adding relation with AMR_Role", + "(using comparison between label and role id)"), + 'construction': """ + ?edge amr:hasAmrRole ?role. + """, + 'clause': """ + ?edge a amr:AMR_Edge ; + amr:hasRoleID ?edgeRoleId. + ?role rdfs:subClassOf* amr:AMR_Role ; + amr:label ?roleLabel. + FILTER ( ?roleLabel != '' ). + FILTER ( ?edgeRoleId = ?roleLabel ). + """, + 'binding': '' + } + +# rule_set['update-amr-edge-role-2'] = { +# 'label': "update-amr-edge-role-2", +# 'comment': ("Update AMR edge by adding relation with AMR_Role", +# "(using comparison between label and role tag)"), +# 'construction': """ +# ?edge amr:hasAmrRole ?role. +# """, +# 'clause': """ +# ?edge a amr:AMR_Edge ; +# amr:hasRoleTag ?edgeRoleId. +# ?role rdfs:subClassOf* amr:AMR_Role ; +# amr:label ?roleLabel. +# FILTER ( ?roleLabel != '' ). +# FILTER ( ?edgeRoleId = ?roleLabel ). +# """, +# 'binding': '' +# } + + +# --------------------------------------------- +# Preprocessing: Addition of root +# --------------------------------------------- + +rule_set['add-amr-root'] = { + 'label': "add-amr-root", + 'comment': ("Add root instance in AMR_Root"), + 'construction': """ + # -- New root + ?newRoot a amr:AMR_Root ; + amr:hasRootLeaf ?leaf ; + amr:hasSentenceID ?graphId ; + amr:hasSentenceStatement ?graphSentence ; + amr:fromAmrLk ?r. + """, + 'clause': """ + # -- Identify root in AMR-LK + ?r a ns3:AMR. + ?r ns3:root ?lkRoot. + ?r ns3:has-id ?graphId. + ?r ns3:has-sentence ?graphSentence. + ?leaf amr:hasVariable ?varRoot. + ?varRoot a amr:AMR_Variable ; + amr:fromAmrLk ?lkRoot. + """, + 'binding':""" + # -- New root + BIND (CONCAT(str(amr:), 'root') AS ?n1). + BIND (CONCAT(?n1, '_', ?graphId) AS ?n2). + BIND (uri(?n2) AS ?newRoot). + """ + } + diff --git a/tenet/scheme/amr_master_rule/preprocessing/amrld_correcting.py b/tenet/scheme/amr_master_rule/preprocessing/amrld_correcting.py new file mode 100644 index 0000000000000000000000000000000000000000..ae4aac513bc415e15f5d7eba269084f8cc78b0c3 --- /dev/null +++ b/tenet/scheme/amr_master_rule/preprocessing/amrld_correcting.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: AMR CTR at 'Data Preprocessing' level +#------------------------------------------------------------------------------ +# Module grouping compositional transduction rule_sets (CTR) for the analysis of +# AMR structures, at 'Data Preprocessing' level +#============================================================================== + +#============================================================================== +# CTR Set (CTR as Sparql querries) +#============================================================================== + +rule_set = {} + + +# --------------------------------------------- +# Fix some bugs with named entities +# --------------------------------------------- + +rule_set['fix-amr-bug-about-system-solar-planet'] = { + 'label': "fix-amr-bug-about-system-solar-planet", + 'comment': "Fix AMR bug about planet named system solar", + 'construction': """ + # -- New concept + ?newC a ns3:NamedEntity ; + rdfs:label ?newLabel. + ?solarSystem a ?newC. + + # -- Tracing original concept as LinkedData and bug + ?c rdfs:subClassOf amr:AMR_Linked_Data. + ?c rdfs:comment 'bug'. + """, + 'clause': """ + # -- Identify bug about planet named system solar + ?c a ns3:NamedEntity. + FILTER ( CONTAINS(str(?c), str(ns4:planet)) ). + ?solarSystem a ?c ; + rdfs:label 'Solar System'. + """, + 'binding':""" + # -- New concept + BIND (str('system') AS ?newLabel). + BIND (CONCAT(str(ns4:), ?newLabel) AS ?n1). + BIND (uri(?n1) AS ?newC). + """ + } + diff --git a/tenet/scheme/amr_master_rule/transduction/__init__.py b/tenet/scheme/amr_master_rule/transduction/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..8d1c8b69c3fce7bea45c73efd06983e3c419a92f --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/__init__.py @@ -0,0 +1 @@ + diff --git a/tenet/scheme/amr_master_rule/transduction/atom_class_extractor.py b/tenet/scheme/amr_master_rule/transduction/atom_class_extractor.py new file mode 100644 index 0000000000000000000000000000000000000000..f40fc45f7d95ed6f4c2d89ef7abd446ce6539ca7 --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/atom_class_extractor.py @@ -0,0 +1,151 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to extract atomic classes +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to extract atomic classes +# Rule: leaf{variable, concept} => atomicClass +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Pattern Search: leaf{variable, concept} +#============================================================================== + +def __search_pattern(graph): + select_data_list = ['?leaf', '?conceptName'] + clause_list = [f'?leaf a amr:AMR_Leaf.', + f'?leaf amr:hasConcept ?leafConcept.', + f'?leafConcept rdfs:subClassOf amr:AMR_Term_Concept.', + f'?leafConcept amr:label ?conceptName.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +#============================================================================== +# Useful Additional Search +#============================================================================== + +def __structure_query_code(graph): + select_data_list = ['?sentenceId'] + clause_list = [] + clause_list.append(f'?root a amr:AMR_Root.') + clause_list.append(f'?root amr:hasSentenceID ?sentenceId.') + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_structure(graph): + query_code = __structure_query_code(graph) + result_set = graph.query(query_code) + return result_set + + +def __search_leaf_in_relation(graph, base_leaf_uri): + select_data_list = ['?inRelationRole', '?inNet'] + clause_list = [f'?inNet a [rdfs:subClassOf* net:Net].', + f'?inNet net:coverBaseNode ?inLeaf.', + ('?inLeaf', '?relation', base_leaf_uri), + f'?relation amr:hasAmrRole ?inRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +def __search_leaf_out_relation(graph, base_leaf_uri): + select_data_list = ['?outRelationRole', '?outNet'] + clause_list = [f'?outNet a [rdfs:subClassOf* net:Net].', + f'?outNet net:coverBaseNode ?outLeaf.', + (base_leaf_uri, '?relation', '?outLeaf'), + f'?relation amr:hasAmrRole ?outRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __get_structure(graph): + structure = 'unknown' + structure_set = __search_structure(graph) + for row in structure_set: + structure = row.sentenceId + return structure + + +def __propagate_relation(graph, target_net, base_leaf): + _, in_relation_set = __search_leaf_in_relation(graph, base_leaf) + for row in in_relation_set: + target_net.input_relation_list += [(row.inNet, row.inRelationRole, _)] + _, out_relation_set = __search_leaf_out_relation(graph, base_leaf) + for row in out_relation_set: + target_net.output_relation_list += [(_, row.outRelationRole, row.outNet)] + + + +#============================================================================== +# Construct Method(s) +#============================================================================== + +def __construct_atom_class_net(graph, leaf, concept_name): + + # -- Net Composition + atom_class_net = net.AtomClassNet(graph) + + # -- Data Computation + atom_class_net.base_node = leaf + atom_class_net.node = leaf + atom_class_net.class_name = concept_name + atom_class_net.structure = __get_structure(graph) + + # -- Net Naming + atom_class_net.naming = concept_name + + # -- Relation Propagation + # __propagate_relation(graph, atom_class_net, leaf) + + # -- Finalization + atom_class_net.finalize() + triple_definition = atom_class_net.generate_triple_definition() + + return atom_class_net, triple_definition + + + +#============================================================================== +# Main Method +#============================================================================== + +def extract_atom_class(graph): + + # -- Rule Initialization + rule_label = 'extract atom classes' + + # -- Search for patterns + _, pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for pattern in pattern_set: + + # -- New Net Construction (from 3 nets) + new_class, triple_list = __construct_atom_class_net( + graph, pattern.leaf, pattern.conceptName) + + # -- Resulting List Update + # class_net_list.append(new_class) + rule_triple_list += triple_list + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/atom_individual_extractor.py b/tenet/scheme/amr_master_rule/transduction/atom_individual_extractor.py new file mode 100644 index 0000000000000000000000000000000000000000..e63801749568451afecebc212c4721f3bc57e162 --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/atom_individual_extractor.py @@ -0,0 +1,172 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to extract atomic individuals +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to extract atomic individuals +# Rule: leaf{variable, concept} => atomicClass +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Pattern Search: Leaf{variable, concept} corresponding to individual +#============================================================================== + +def __search_pattern(graph): + select_data_list = ['?baseLeaf', '?valueLabel', '?classNet'] + clause_list = [f'?baseLeaf a amr:AMR_Leaf.', + f'?baseLeaf amr:hasConcept ?leafConcept.', + f'?baseLeaf ?edge ?value.', + f'?edge amr:hasRoleID ?roleID.', + f'VALUES ?roleID {{"name"}}', + f'?value a amr:AMR_Value.', + f'?value rdfs:label ?valueLabel.', + f'?classNet a [rdfs:subClassOf* net:Class_Net].', + f'?classNet net:coverBaseNode ?baseLeaf.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +#============================================================================== +# Useful Additional Search +#============================================================================== + +def __structure_query_code(graph): + select_data_list = ['?sentenceId'] + clause_list = [] + clause_list.append(f'?root a amr:AMR_Root.') + clause_list.append(f'?root amr:hasSentenceID ?sentenceId.') + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_structure(graph): + query_code = __structure_query_code(graph) + result_set = graph.query(query_code) + return result_set + + +def __search_leaf_in_relation(graph, base_leaf_uri): + select_data_list = ['?inRelationRole', '?inNet'] + clause_list = [f'?inNet a [rdfs:subClassOf* net:Net].', + f'?inNet net:coverBaseNode ?inLeaf.', + ('?inLeaf', '?relation', base_leaf_uri), + f'?relation amr:hasAmrRole ?inRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +def __search_leaf_out_relation(graph, base_leaf_uri): + select_data_list = ['?outRelationRole', '?outNet'] + clause_list = [f'?outNet a [rdfs:subClassOf* net:Net].', + f'?outNet net:coverBaseNode ?outLeaf.', + (base_leaf_uri, '?relation', '?outLeaf'), + f'?relation amr:hasAmrRole ?outRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __get_structure(graph): + structure = 'unknown' + structure_set = __search_structure(graph) + for row in structure_set: + structure = row.sentenceId + return structure + + +def __define_naming(value_label): + value_label = value_label.replace(' ', '#') + value_label = value_label.replace('-', '#') + word_set = value_label.split('#') + first = True + for word in word_set: + if first: + naming = word + first = False + else: + naming += word.capitalize() + return naming + + +def __propagate_relation(graph, target_net, base_leaf): + _, in_relation_set = __search_leaf_in_relation(graph, base_leaf) + for row in in_relation_set: + target_net.input_relation_list += [(row.inNet, row.inRelationRole, _)] + _, out_relation_set = __search_leaf_out_relation(graph, base_leaf) + for row in out_relation_set: + target_net.output_relation_list += [(_, row.outRelationRole, row.outNet)] + + + +#============================================================================== +# Construct Method(s) +#============================================================================== + +def __construct_individual_net( + graph, base_leaf, value_label, mother_class_net): + + # -- Net Composition + individual_net = net.IndividualNet(graph) + + # -- Data Computation + individual_net.base_node = base_leaf + individual_net.node = base_leaf + individual_net.individual_label = value_label + individual_net.mother_class_net = mother_class_net + individual_net.structure = __get_structure(graph) + + # -- Net Naming + individual_net.naming = __define_naming(value_label) + + # -- Relation Propagation + # __propagate_relation(graph, individual_net, base_leaf) + + # -- Finalization + individual_net.finalize() + triple_definition = individual_net.generate_triple_definition() + + return individual_net, triple_definition + + + +#============================================================================== +# Main Method +#============================================================================== + +def extract_atom_individual(graph): + + # -- Rule Initialization + rule_label = 'extract atom individuals' + + # -- Search for patterns + _, pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for pattern in pattern_set: + + # -- New Net Construction (from 3 nets) + new_class, triple_list = __construct_individual_net( + graph, pattern.baseLeaf, pattern.valueLabel, pattern.classNet) + + # -- Resulting List Update + # class_net_list.append(new_class) + rule_triple_list += triple_list + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/atom_phenomena_extractor.py b/tenet/scheme/amr_master_rule/transduction/atom_phenomena_extractor.py new file mode 100644 index 0000000000000000000000000000000000000000..83be091f73e5f840c3d57c3ff16891a51e30ab29 --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/atom_phenomena_extractor.py @@ -0,0 +1,160 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to extract atomic individuals +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to extract atomic individuals +# Rule: leaf{variable, concept} => atomicClass +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Pattern Search: Leaf{variable, concept} corresponding to individual +#============================================================================== + +def __search_pattern(graph): + select_data_list = ['?baseLeaf', '?phenomenaLabel', '?relationConceptPhenomena', '?relationConceptLabel'] + clause_list = [f'?baseLeaf a amr:AMR_Leaf.', + f'?baseLeaf amr:hasConcept ?concept.', + f'?concept rdfs:subClassOf amr:AMR_Relation_Concept.', + f'?concept amr:hasPhenomenaLink ?relationConceptPhenomena.', + f'?concept amr:label ?relationConceptLabel.', + f'?relationConceptPhenomena amr:label ?phenomenaLabel.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Useful Additional Search +#============================================================================== + +def __structure_query_code(graph): + select_data_list = ['?sentenceId'] + clause_list = [] + clause_list.append(f'?root a amr:AMR_Root.') + clause_list.append(f'?root amr:hasSentenceID ?sentenceId.') + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_structure(graph): + query_code = __structure_query_code(graph) + result_set = graph.query(query_code) + return result_set + + +def __search_leaf_in_relation(graph, base_leaf_uri): + select_data_list = ['?inRelationRole', '?inNet'] + clause_list = [f'?inNet a [rdfs:subClassOf* net:Net].', + f'?inNet net:coverBaseNode ?inLeaf.', + ('?inLeaf', '?relation', base_leaf_uri), + f'?relation amr:hasAmrRole ?inRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +def __search_leaf_out_relation(graph, base_leaf_uri): + select_data_list = ['?outRelationRole', '?outNet'] + clause_list = [f'?outNet a [rdfs:subClassOf* net:Net].', + f'?outNet net:coverBaseNode ?outLeaf.', + (base_leaf_uri, '?relation', '?outLeaf'), + f'?relation amr:hasAmrRole ?outRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __get_structure(graph): + structure = 'unknown' + structure_set = __search_structure(graph) + for row in structure_set: + structure = row.sentenceId + return structure + + +def __propagate_relation(graph, target_net, base_leaf): + _, in_relation_set = __search_leaf_in_relation(graph, base_leaf) + for row in in_relation_set: + target_net.input_relation_list += [(row.inNet, row.inRelationRole, _)] + _, out_relation_set = __search_leaf_out_relation(graph, base_leaf) + for row in out_relation_set: + target_net.output_relation_list += [(_, row.outRelationRole, row.outNet)] + + + +#============================================================================== +# Construct Method(s) +#============================================================================== + +def __construct_phenomena_net( + graph, base_leaf, phenomena_label, relation_concept_phenomena, relation_concept_label): + + # -- Net Composition + phenomena_net = net.PhenomenaNet(graph) + + # -- Data Computation + phenomena_net.base_node = base_leaf + phenomena_net.node = base_leaf + phenomena_net.phenomena_type = relation_concept_phenomena + phenomena_net.phenomena_ref = relation_concept_label + phenomena_net.structure = __get_structure(graph) + + # -- Net Naming + phenomena_net.naming = phenomena_label + + # -- Relation Propagation + # __propagate_relation(graph, phenomena_net, base_leaf) + + # -- Finalization + phenomena_net.finalize() + triple_definition = phenomena_net.generate_triple_definition() + + return phenomena_net, triple_definition + + + +#============================================================================== +# Main Method +#============================================================================== + +def extract_atom_phenomena(graph): + + # -- Rule Initialization + rule_label = 'extract atom phenomena' + + # -- Search for patterns + _, pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for pattern in pattern_set: + + # -- New Net Construction (from 3 nets) + new_class, triple_list = __construct_phenomena_net( + graph, + pattern.baseLeaf, + pattern.phenomenaLabel, + pattern.relationConceptPhenomena, + pattern.relationConceptLabel) + + # -- Resulting List Update + # class_net_list.append(new_class) + rule_triple_list += triple_list + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/atom_property_extractor.py b/tenet/scheme/amr_master_rule/transduction/atom_property_extractor.py new file mode 100644 index 0000000000000000000000000000000000000000..4cf2466bde94781bf5821d87b62f439ffca3a898 --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/atom_property_extractor.py @@ -0,0 +1,184 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to extract atomic properties +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to extract atomic properties +# Rule: leaf{variable, amrTermConcept} => atomicProperty +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction import rdfterm_computer +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Pattern Search: Leaf{variable, amrPrecicateConcept} +#============================================================================== + +def __search_pattern(graph): + select_data_list = ['?baseLeaf', '?predicateLabel'] + clause_list = [f'?baseLeaf a amr:AMR_Leaf.', + f'?baseLeaf amr:hasConcept ?leafConcept.', + f'?leafConcept rdfs:subClassOf amr:AMR_Predicat_Concept.', + f'?leafConcept amr:label ?predicateLabel.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +#============================================================================== +# Useful Additional Search +#============================================================================== + +def __structure_query_code(graph): + select_data_list = ['?sentenceId'] + clause_list = [] + clause_list.append(f'?root a amr:AMR_Root.') + clause_list.append(f'?root amr:hasSentenceID ?sentenceId.') + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_structure(graph): + query_code = __structure_query_code(graph) + result_set = graph.query(query_code) + return result_set + + +def __target_argument_pattern_query_code(graph, base_leaf_uri): + select_data_list = ['?argLeaf'] + clause_list = [] + clause_list.append((base_leaf_uri, '?relation', '?argLeaf')) + clause_list.append(f'?relation amr:hasAmrRole ?someArgRole.') + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_target_argument(graph, base_leaf_uri): + query_code = __target_argument_pattern_query_code(graph, base_leaf_uri) + result_set = graph.query(query_code) + return result_set + + +def __search_leaf_in_relation(graph, base_leaf_uri): + select_data_list = ['?inRelationRole', '?inNet'] + clause_list = [f'?inNet a [rdfs:subClassOf* net:Net].', + f'?inNet net:coverBaseNode ?inLeaf.', + ('?inLeaf', '?relation', base_leaf_uri), + f'?relation amr:hasAmrRole ?inRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +def __search_leaf_out_relation(graph, base_leaf_uri): + select_data_list = ['?outRelationRole', '?outNet'] + clause_list = [f'?outNet a [rdfs:subClassOf* net:Net].', + f'?outNet net:coverBaseNode ?outLeaf.', + (base_leaf_uri, '?relation', '?outLeaf'), + f'?relation amr:hasAmrRole ?outRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __get_structure(graph): + structure = 'unknown' + structure_set = __search_structure(graph) + for row in structure_set: + structure = row.sentenceId + return structure + + +def __define_naming(predicate_label): + naming = predicate_label.split('-')[0] + return naming + + +def __propagate_relation(graph, target_net, base_leaf): + + _, in_relation_set = __search_leaf_in_relation(graph, base_leaf) + for row in in_relation_set: + target_net.input_relation_list += [(row.inNet, row.inRelationRole, _)] + + _, out_relation_set = __search_leaf_out_relation(graph, base_leaf) + for row in out_relation_set: + target_net.output_relation_list += [(_, row.outRelationRole, row.outNet)] + + + +#============================================================================== +# Construct Method(s) +#============================================================================== + +def __construct_atom_property_net(graph, base_leaf, predicate_label): + + # -- Net Composition + atom_property_net = net.AtomPropertyNet(graph) + + # -- Data Computation + atom_property_net.base_node = base_leaf + atom_property_net.node = base_leaf + atom_property_net.property_type = 'owl:ObjectProperty' + atom_property_net.core_role = 'true' + atom_property_net.structure = __get_structure(graph) + + # -- Target Argument + target_argument_set = __search_target_argument(graph, base_leaf) + for data in target_argument_set: + atom_property_net.target_argument_node += [data.argLeaf] + + # -- Net Naming + naming = __define_naming(predicate_label) + atom_property_net.naming = naming + atom_property_net.property_name = naming + atom_property_net.property_name01 = f'{naming}ing' + atom_property_net.property_name10 = f'{naming}-by' + atom_property_net.property_name12 = f'{naming}-of' + + # -- Relation Propagation + # __propagate_relation(graph, atom_property_net, base_leaf) + + # -- Finalization + atom_property_net.finalize() + triple_definition = atom_property_net.generate_triple_definition() + + return atom_property_net, triple_definition + + + +#============================================================================== +# Main Method +#============================================================================== + +def extract_atom_property(graph): + + # -- Rule Initialization + rule_label = 'extract atomic properties' + + # -- Search for patterns + _, pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for pattern in pattern_set: + + # -- New Net Construction (from 3 nets) + new_net, triple_list = __construct_atom_property_net( + graph, pattern.baseLeaf, pattern.predicateLabel) + + # -- Resulting List Update + rule_triple_list += triple_list + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/atom_relation_propagator.py b/tenet/scheme/amr_master_rule/transduction/atom_relation_propagator.py new file mode 100644 index 0000000000000000000000000000000000000000..459a12fab52c8716faee8167ed399cd7a12f67ad --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/atom_relation_propagator.py @@ -0,0 +1,92 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to extract atomic individuals +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to extract atomic individuals +# Rule: leaf{variable, concept} => atomicClass +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Pattern Search: Leaf{variable, concept} corresponding to individual +#============================================================================== + +def __search_pattern(graph): + select_data_list = ['?net'] + clause_list = [f'?net a [rdfs:subClassOf* net:Net].'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +#============================================================================== +# Useful Additional Search +#============================================================================== + +def __search_leaf_in_relation(graph, base_leaf_uri): + select_data_list = ['?inRelationRole', '?inNet'] + clause_list = [f'?inNet a [rdfs:subClassOf* net:Net].', + f'?inNet net:coverBaseNode ?inLeaf.', + ('?inLeaf', '?relation', base_leaf_uri), + f'?relation amr:hasAmrRole ?inRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +def __search_leaf_out_relation(graph, base_leaf_uri): + select_data_list = ['?outRelationRole', '?outNet'] + clause_list = [f'?outNet a [rdfs:subClassOf* net:Net].', + f'?outNet net:coverBaseNode ?outLeaf.', + (base_leaf_uri, '?relation', '?outLeaf'), + f'?relation amr:hasAmrRole ?outRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __propagate_relation(graph, target_net, base_leaf): + _, in_relation_set = __search_leaf_in_relation(graph, base_leaf) + for row in in_relation_set: + target_net.input_relation_list += [(row.inNet, row.inRelationRole, _)] + _, out_relation_set = __search_leaf_out_relation(graph, base_leaf) + for row in out_relation_set: + target_net.output_relation_list += [(_, row.outRelationRole, row.outNet)] + + + +#============================================================================== +# Main Method +#============================================================================== + +def propagate_atom_relation(graph): + + # -- Rule Initialization + rule_label = 'propagate atom relations' + + # -- Search for patterns + _, pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for pattern in pattern_set: + target_net = net.Net(graph, pattern.net) + if len(target_net.base_node) > 0: + __propagate_relation(graph, target_net, target_net.base_node[0]) + rule_triple_list += target_net.generate_net_relation_triples() + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/atom_value_extractor.py b/tenet/scheme/amr_master_rule/transduction/atom_value_extractor.py new file mode 100644 index 0000000000000000000000000000000000000000..4bed1cb88082aaf540796a29a84572c653698803 --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/atom_value_extractor.py @@ -0,0 +1,149 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to extract atomic individuals +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to extract atomic individuals +# Rule: leaf{variable, concept} => atomicClass +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Pattern Search: Leaf{variable, concept} corresponding to individual +#============================================================================== + +def __search_pattern(graph): + select_data_list = ['?valueLabel'] + clause_list = [f'?value a amr:AMR_Value.', + f'?value rdfs:label ?valueLabel.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +#============================================================================== +# Useful Additional Search +#============================================================================== + +def __structure_query_code(graph): + select_data_list = ['?sentenceId'] + clause_list = [] + clause_list.append(f'?root a amr:AMR_Root.') + clause_list.append(f'?root amr:hasSentenceID ?sentenceId.') + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_structure(graph): + query_code = __structure_query_code(graph) + result_set = graph.query(query_code) + return result_set + + +def __search_leaf_in_relation(graph, base_leaf_uri): + select_data_list = ['?inRelationRole', '?inNet'] + clause_list = [f'?inNet a [rdfs:subClassOf* net:Net].', + f'?inNet net:coverBaseNode ?inLeaf.', + ('?inLeaf', '?relation', base_leaf_uri), + f'?relation amr:hasAmrRole ?inRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + +def __search_leaf_out_relation(graph, base_leaf_uri): + select_data_list = ['?outRelationRole', '?outNet'] + clause_list = [f'?outNet a [rdfs:subClassOf* net:Net].', + f'?outNet net:coverBaseNode ?outLeaf.', + (base_leaf_uri, '?relation', '?outLeaf'), + f'?relation amr:hasAmrRole ?outRelationRole.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __get_structure(graph): + structure = 'unknown' + structure_set = __search_structure(graph) + for row in structure_set: + structure = row.sentenceId + return structure + + +def __define_naming(value_label): + value_label = value_label.replace(' ', '#') + value_label = value_label.replace('-', '#') + word_set = value_label.split('#') + first = True + for word in word_set: + if first: + naming = word + first = False + else: + naming += word.capitalize() + return naming + + + +#============================================================================== +# Construct Method(s) +#============================================================================== + +def __construct_value_net( + graph, value_label): + + # -- Net Composition + value_net = net.ValueNet(graph) + + # -- Data Computation + value_net.value_label = value_label + value_net.structure = __get_structure(graph) + + # -- Net Naming + value_net.naming = __define_naming(value_label) + + # -- Finalization + value_net.finalize() + triple_definition = value_net.generate_triple_definition() + + return value_net, triple_definition + + + +#============================================================================== +# Main Method +#============================================================================== + +def extract_atom_value(graph): + + # -- Rule Initialization + rule_label = 'extract atom values' + + # -- Search for patterns + _, pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for pattern in pattern_set: + + # -- New Net Construction (from 3 nets) + new_class, triple_list = __construct_value_net(graph, pattern.valueLabel) + + # -- Resulting List Update + # class_net_list.append(new_class) + rule_triple_list += triple_list + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/composite_class_extractor_1.py b/tenet/scheme/amr_master_rule/transduction/composite_class_extractor_1.py new file mode 100644 index 0000000000000000000000000000000000000000..31e9497138bb801a2126116f15c52360da516824 --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/composite_class_extractor_1.py @@ -0,0 +1,164 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to extract composite classes (rule 1) +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to extract composite classes +# Rule: property(arg0:class, arg1:class) => compositeClass +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Pattern Search: property(arg0:class, arg1:class) +#============================================================================== + +def __search_pattern(graph): + select_data_list = ['?property_net', '?class_net_0', '?class_net_1'] + clause_list = [f'?property_net a [rdfs:subClassOf* net:Property_Net].', + f'FILTER NOT EXISTS {{ ?property_net a net:Deprecated_Net. }}', + f'?class_net_0 a [rdfs:subClassOf* net:Class_Net].', + f'FILTER NOT EXISTS {{ ?class_net_0 a net:Deprecated_Net. }}', + f'?class_net_1 a [rdfs:subClassOf* net:Class_Net].', + f'FILTER NOT EXISTS {{ ?class_net_1 a net:Deprecated_Net. }}', + f'?property_net amr:role_ARG0 ?class_net_0.', + f'?property_net amr:role_ARG1 ?class_net_1.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Net Checking +#============================================================================== + +def __verify_disjoint_cover(class_net_0, class_net_1): + check = True + for node in class_net_0.node: + if node in class_net_1.node: check = False + return check + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __filter_relation(relation_list): + result_list = [] + for relation in relation_list: + check = True + (s, p, o) = relation + if s == o: check = False + if check: result_list.append(relation) + return result_list + + +def __propagate_relation(target_net, base_net): + # -- target_net.input_relation_list = base_net.input_relation_list + out_relation_list = __filter_relation(base_net.output_relation_list) + target_net.output_relation_list = out_relation_list + + + +#============================================================================== +# Construct Method(s) +#============================================================================== + +def __construct_restriction_net(graph, property_net_1, property_net_2): + + restriction_net = net.RestrictionNet(graph) + restriction_net.compose(property_net_1, property_net_2) + + # -- Data Computation + restriction_net.restriction_property = property_net_1.uri + restriction_net.restriction_net_value = property_net_2.uri + + # -- Relation Propagation: None + + # -- Net Naming + restriction_net.naming = define_restriction_naming(property_net_1, property_net_2) + + # -- Finalization + restriction_net.finalize() + triple_list = restriction_net.generate_triple_definition() + + return restriction_net, triple_list + + + +def __construct_composite_class_net( + graph, base_class_net, core_property_net, target_class_net): + + # -- Net Composition + composite_class_net = net.CompositePropertyNet(graph) + composite_class_net.compose(base_class_net, core_property_net, target_class_net) + + # -- Data Computation + composite_class_net.mother_class_net = base_class_net.uri + + # -- Restriction Computation + restriction_net, triple_list_1 = __construct_restriction_net(graph, core_property_net, target_class_net) + composite_class_net.restriction = restriction_net.uri + + # -- Relation Propagation + __propagate_relation(composite_class_net, base_class_net) + + # -- Net Naming + composite_class_net.naming = define_composite_naming_1( + base_class_net, core_property_net, target_class_net) + + # -- Finalization + composite_class_net.finalize() + triple_list_2 = composite_class_net.generate_triple_definition() + result_triple_list = triple_list_1 + triple_list_2 + + return composite_class_net, result_triple_list + + + +#============================================================================== +# Main Method +#============================================================================== + +def extract_composite_class_1(graph): + + # -- Rule Initialization + rule_label = 'extract composite classes (1)' + + # -- Search for patterns + _, pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for pattern in pattern_set: + + # -- Net Selection + property_net = net.PropertyNet(graph, uri=pattern.property_net) + class_net_0 = net.ClassNet(graph, uri=pattern.class_net_0) + class_net_1 = net.ClassNet(graph, uri=pattern.class_net_1) + + # -- Condition: disjoint cover + if __verify_disjoint_cover(class_net_0, class_net_1): + # print(f' *** DEVTEST *** {selection_2.class_net}') + + # -- New Net Construction (from 3 nets) + new_class, triple_list = __construct_composite_class_net( + graph, class_net_0, property_net, class_net_1) + + # -- Resulting List Update + # class_net_list.append(new_class) + rule_triple_list += triple_list + + # -- Deprecation: Origin Class Net + rule_triple_list += class_net_0.deprecate() + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/composite_class_extractor_2.py b/tenet/scheme/amr_master_rule/transduction/composite_class_extractor_2.py new file mode 100644 index 0000000000000000000000000000000000000000..997f7e058abc2df52e56808bd36f3ca99c34cfce --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/composite_class_extractor_2.py @@ -0,0 +1,164 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to extract composite classes (rule 2) +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to extract composite classes +# Rule: property(arg1:class, arg2:class) => compositeClass +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Pattern Search: property(arg1:class, arg2:class) +#============================================================================== + +def __search_pattern(graph): + select_data_list = ['?property_net', '?class_net_1', '?class_net_2'] + clause_list = [f'?property_net a [rdfs:subClassOf* net:Property_Net].', + f'FILTER NOT EXISTS {{ ?property_net a net:Deprecated_Net. }}', + f'?class_net_1 a [rdfs:subClassOf* net:Class_Net].', + f'FILTER NOT EXISTS {{ ?class_net_1 a net:Deprecated_Net. }}', + f'?class_net_2 a [rdfs:subClassOf* net:Class_Net].', + f'FILTER NOT EXISTS {{ ?class_net_2 a net:Deprecated_Net. }}', + f'?property_net amr:role_ARG1 ?class_net_1.', + f'?property_net amr:role_ARG2 ?class_net_2.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Checking Method(s) +#============================================================================== + +def __verify_disjoint_cover(class_net_0, class_net_1): + check = True + for node in class_net_0.node: + if node in class_net_1.node: check = False + return check + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __filter_relation(relation_list): + result_list = [] + for relation in relation_list: + check = True + (s, p, o) = relation + if s == o: check = False + if check: result_list.append(relation) + return result_list + + +def __propagate_relation(target_net, base_net): + # -- target_net.input_relation_list = base_net.input_relation_list + out_relation_list = __filter_relation(base_net.output_relation_list) + target_net.output_relation_list = out_relation_list + + + +#============================================================================== +# Construct Method(s) +#============================================================================== + +def __construct_restriction_net(graph, property_net_1, property_net_2): + + restriction_net = net.RestrictionNet(graph) + restriction_net.compose(property_net_1, property_net_2) + + # -- Data Computation + restriction_net.restriction_property = property_net_1.uri + restriction_net.restriction_net_value = property_net_2.uri + + # -- Relation Propagation: None + + # -- Net Naming + restriction_net.naming = define_restriction_naming(property_net_1, property_net_2) + + # -- Finalization + restriction_net.finalize() + triple_list = restriction_net.generate_triple_definition() + + return restriction_net, triple_list + + + +def __construct_composite_class_net_from_3_nets( + graph, base_class_net, core_property_net, target_class_net): + + # -- Net Composition + composite_class_net = net.CompositePropertyNet(graph) + composite_class_net.compose(base_class_net, core_property_net, target_class_net) + + # -- Data Computation + composite_class_net.mother_class_net = base_class_net.uri + + # -- Restriction Computation + restriction_net, triple_list_1 = __construct_restriction_net(graph, core_property_net, target_class_net) + composite_class_net.restriction = restriction_net.uri + + # -- Relation Propagation + __propagate_relation(composite_class_net, base_class_net) + + # -- Net Naming + composite_class_net.naming = define_composite_naming_1( + base_class_net, core_property_net, target_class_net) + + # -- Finalization + composite_class_net.finalize() + triple_list_2 = composite_class_net.generate_triple_definition() + result_triple_list = triple_list_1 + triple_list_2 + + return composite_class_net, result_triple_list + + + +#============================================================================== +# Main Method +#============================================================================== + +def extract_composite_class_2(graph): + + # -- Rule Initialization + rule_label = 'extract composite classes (2)' + + # -- Search for patterns + _, pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for pattern in pattern_set: + + # -- Net Selection + property_net = net.PropertyNet(graph, uri=pattern.property_net) + class_net_1 = net.ClassNet(graph, uri=pattern.class_net_1) + class_net_2 = net.ClassNet(graph, uri=pattern.class_net_2) + + # -- Condition: disjoint cover + if __verify_disjoint_cover(class_net_1, class_net_2): + # print(f' *** DEVTEST *** {selection_2.class_net}') + + # -- New Net Construction (from 3 nets) + new_class, triple_list = __construct_composite_class_net_from_3_nets( + graph, class_net_1, property_net, class_net_2) + + # -- Resulting List Update + # class_net_list.append(new_class) + rule_triple_list += triple_list + + # -- Deprecation: Origin Class Net + rule_triple_list += class_net_1.deprecate() + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/phenomena_mod_analyzer_1.py b/tenet/scheme/amr_master_rule/transduction/phenomena_mod_analyzer_1.py new file mode 100644 index 0000000000000000000000000000000000000000..dd2090e6ffd4a1775e2a028ec1e39fafbfbfbe32 --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/phenomena_mod_analyzer_1.py @@ -0,0 +1,182 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to analyze phenomena mod (rule 1) +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to analyse modifier phenomena (mod) +# Rule: mod(class, class) => compositeClass +#============================================================================== + +import rdflib +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_axiom_naming +from transduction.naming_computer import define_composite_naming_2 + + +#============================================================================== +# Pattern Search: mod(class, class) +#============================================================================== + +MOD_RELATION = 'amr:role_mod' + +def __search_pattern(graph): + select_data_list = ['?class_net_1', '?class_net_2'] + clause_list = [f'?class_net_1 a [rdfs:subClassOf* net:Class_Net].', + f'?class_net_2 a [rdfs:subClassOf* net:Class_Net].', + f'?class_net_1 {MOD_RELATION} ?class_net_2.'] + query_code = generate_select_query(graph, select_data_list, clause_list) + result_set = graph.query(query_code) + return query_code, result_set + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __extract_naming(net, default='none'): + naming = f'{default}' + naming_list = net.naming + if len(naming_list) > 0: + assert len(naming_list) == 1, f'Houston, we have a problem: too many naming' + naming = naming_list[0] + return naming + +def __define_feature_restriction_naming(class_net): + name = __extract_naming(class_net, default='something') + return f'{name}-feature' + +def __define_composite_naming(class_net_1, class_net_2): + name_1 = __extract_naming(class_net_1, default='something') + name_2 = __extract_naming(class_net_2, default='something') + return f'{name_2}-{name_1}' + + +def __filter_relation(relation_list): + result_list = [] + for relation in relation_list: + check = True + (s, p, o) = relation + if s == o: check = False + if p == MOD_RELATION: check = False + if check: result_list.append(relation) + return result_list + +def __propagate_relation(target_net, base_net): + target_net.input_relation_list = base_net.input_relation_list + out_relation_list = __filter_relation(base_net.output_relation_list) + target_net.output_relation_list = out_relation_list + + + +#============================================================================== +# Construct Method(s) +#============================================================================== + +def __construct_feature_restriction_net(graph, class_net): # TODO + + restriction_net = net.RestrictionNet(graph) + restriction_net.compose(class_net) + + # -- Data Computation + restriction_net.restriction_property = '--hasFeature--' # TODO + restriction_net.restriction_net_value = class_net.uri + + # -- Relation Propagation: None + + # -- Net Naming + restriction_net.naming = __define_feature_restriction_naming(class_net) + + # -- Finalization + restriction_net.finalize() + triple_list = restriction_net.generate_triple_definition() + + return restriction_net, triple_list + + + +def __construct_composite_class_net(graph, class_net_1, class_net_2): + + # -- Net Composition + composite_class_net = net.CompositeClassNet(graph) + composite_class_net.compose(class_net_1, class_net_2) + + # -- Data Computation + composite_class_net.mother_class_net = class_net_1.uri + + # -- Restriction Computation + triple_list_1 = [] + # restriction_net, triple_list_1 = __construct_feature_restriction_net(graph, class_net) + # composite_class_net.restriction = restriction_net.uri + + # -- Net Naming + composite_class_net.naming = __define_composite_naming(class_net_1, class_net_2) + + # -- Relation Propagation + __propagate_relation(composite_class_net, class_net_1) + + # -- Finalization + composite_class_net.finalize() + triple_list_2 = composite_class_net.generate_triple_definition() + result_triple_list = triple_list_1 + triple_list_2 + + return composite_class_net, result_triple_list + + + +def __construct_individual_net(graph, class_net): + + # -- Net Composition + individual_net = net.IndividualNet(graph) + individual_net.compose(class_net) + + # -- Data Computation + individual_net.base_class_name = f'Feature' + individual_net.mother_class_net = class_net.uri + + # -- Net Naming + individual_net.naming = f'{__extract_naming(class_net, default="something")}' + individual_net.individual_label = f'{__extract_naming(class_net, default="something")}' + + # -- Finalization + individual_net.finalize() + result_triple_list = individual_net.generate_triple_definition() + + return individual_net, result_triple_list + + + +#============================================================================== +# Main Method: analyze_phenomena_or_1 +#============================================================================== + +def analyze_phenomena_mod_1(graph): + + # -- Rule Initialization + rule_label = 'analyze modifier phenomena (mod)' + + # -- Search for patterns + _, pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for pattern in pattern_set: + class_net_1 = net.ClassNet(graph, uri=pattern.class_net_1) + class_net_2 = net.ClassNet(graph, uri=pattern.class_net_2) + + # -- New Net Construction(s) + _, triple_list_1 = __construct_composite_class_net(graph, class_net_1, class_net_2) + _, triple_list_2 = __construct_individual_net(graph, class_net_2) + + # -- Resulting List Update + rule_triple_list += triple_list_1 + triple_list_2 + + # -- Deprecation: Origin Class Net + rule_triple_list += class_net_1.deprecate() + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/phenomena_or_analyzer_1.py b/tenet/scheme/amr_master_rule/transduction/phenomena_or_analyzer_1.py new file mode 100644 index 0000000000000000000000000000000000000000..8283ee1d45006df0a62b820e009b374dc02e8159 --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/phenomena_or_analyzer_1.py @@ -0,0 +1,212 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to conjunctive phenomena or (rule 1) +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to analyse conjunctive phenomena (or) +# Rule: property(class, or_phenomena) => compositeClass +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Pattern Search: property(class, or_phenomena) +#============================================================================== + +def __rule_pattern_query_code(graph): + select_data_list = ['?property_net', '?class_net', '?phenomena_net'] + clause_list = [] + clause_list.append(f'?property_net a [rdfs:subClassOf* net:Property_Net].') + clause_list.append(f'?class_net a [rdfs:subClassOf* net:Class_Net].') + clause_list.append(f'?phenomena_net a [rdfs:subClassOf* net:Phenomena_Net].') + clause_list.append(f'?phenomena_net net:hasPhenomenaType amr:phenomena_conjunction_or.') + clause_list.append(f'?property_net amr:role_ARG0 ?class_net.') + clause_list.append(f'?property_net amr:role_ARG1 ?phenomena_net.') + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_pattern(graph): + query_code = __rule_pattern_query_code(graph) + rule_pattern_set = graph.query(query_code) + return rule_pattern_set + + + +#============================================================================== +# Useful Additional Search +#============================================================================== + +def __class_op_pattern_query_code(graph, phenomena_net_uri, num): + assert 1 <= num <= 9, f'invalid number ({num})' + select_data_list = ['?class_net'] + clause_list = [f'?class_net a [rdfs:subClassOf* net:Class_Net].'] + clause_list.append((phenomena_net_uri, f'amr:role_op{num}', '?class_net')) + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_class_phenomena_operator(graph, phenomena_net_uri): + op_set = [] + for num in range(1, 9+1): + query_code = __class_op_pattern_query_code(graph, phenomena_net_uri, num) + op_set += graph.query(query_code) + return op_set + + + +#============================================================================== +# Useful Computation Method(s) +#============================================================================== + +def __filter_relation(relation_list): + result_list = [] + for relation in relation_list: + check = True + (s, p, o) = relation + if s == o: check = False + if check: result_list.append(relation) + return result_list + + +def __propagate_relation(target_net, base_net): + # -- target_net.input_relation_list = base_net.input_relation_list + out_relation_list = __filter_relation(base_net.output_relation_list) + target_net.output_relation_list = out_relation_list + + + +#============================================================================== +# Construct Method(s) +#============================================================================== + +def __construct_restriction_net(graph, property_net_1, property_net_2): + + restriction_net = net.RestrictionNet(graph) + restriction_net.compose(property_net_1, property_net_2) + + # -- Data Computation + restriction_net.restriction_property = property_net_1.uri + restriction_net.restriction_net_value = property_net_2.uri + + # -- Relation Propagation: None + + # -- Net Naming + restriction_net.naming = define_restriction_naming(property_net_1, property_net_2) + + # -- Finalization + restriction_net.finalize() + triple_list = restriction_net.generate_triple_definition() + + return restriction_net, triple_list + + + +def __construct_composite_class_net_from_3_nets( + graph, base_class_net, core_property_net, target_class_net): + + # -- Net Composition + composite_class_net = net.CompositePropertyNet(graph) + composite_class_net.compose(base_class_net, core_property_net, target_class_net) + + # -- Data Computation + composite_class_net.mother_class_net = base_class_net.uri + + # -- Restriction Computation + restriction_net, triple_list_1 = __construct_restriction_net(graph, core_property_net, target_class_net) + composite_class_net.restriction = restriction_net.uri + + # -- Relation Propagation + __propagate_relation(composite_class_net, base_class_net) + + # -- Net Naming + composite_class_net.naming = define_composite_naming_1( + base_class_net, core_property_net, target_class_net) + + # -- Finalization + composite_class_net.finalize() + triple_list_2 = composite_class_net.generate_triple_definition() + result_triple_list = triple_list_1 + triple_list_2 + + return composite_class_net, result_triple_list + + + +def __construct_class_union_net(graph, base_class_net, class_net_list): + + # -- Net Composition + class_union_net = net.PropertyUnionNet(graph) + class_union_net.compose(base_class_net, class_net_list) + + # -- Data Computation: None + + # -- Restriction Computation: None + + # -- Relation Propagation + __propagate_relation(class_union_net, base_class_net) + + # -- Net Naming + class_union_net.naming = define_union_naming(base_class_net) + + # -- Finalization + class_union_net.finalize() + triple_list = class_union_net.generate_triple_definition() + + return class_union_net, triple_list + + +#============================================================================== +# Main Method: analyze_phenomena_or_1 +#============================================================================== + +def analyze_phenomena_or_1(graph): + + # -- Rule Initialization + rule_label = 'analyze "or" phenomena (1)' + + # -- Search for patterns + rule_pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for selection_1 in rule_pattern_set: + + # -- Net Selection + class_net_1 = net.ClassNet(graph, uri=selection_1.class_net) + property_net = net.PropertyNet(graph, uri=selection_1.property_net) + phenomena_net = net.PhenomenaNet(graph, uri=selection_1.phenomena_net) + + # -- Search for phenomena operators + class_operator_set = __search_class_phenomena_operator(graph, phenomena_net.uri) + + # -- Selection Analyzing (2) + class_net_list = [] + for selection_2 in class_operator_set: + # print(f' *** DEVTEST *** {selection_2.class_net}') + + # -- Net Selection + class_net_2 = net.ClassNet(graph, uri=selection_2.class_net) + + # -- New Net Construction (from 3 nets) + new_class, triple_list = __construct_composite_class_net_from_3_nets( + graph, class_net_1, property_net, class_net_2) + + # -- Resulting List Update + class_net_list.append(new_class) + rule_triple_list += triple_list + + # -- Deprecation: Origin Class Net + rule_triple_list += class_net_1.deprecate() + + # -- New Net Construction (as union of properties) + # _, triple_list = __construct_class_union_net(graph, class_net_1, class_net_list) + # rule_triple_list += triple_list + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/phenomena_or_analyzer_2.py b/tenet/scheme/amr_master_rule/transduction/phenomena_or_analyzer_2.py new file mode 100644 index 0000000000000000000000000000000000000000..88955c5a726895760ed8c56c8b4bb58842ca973c --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/phenomena_or_analyzer_2.py @@ -0,0 +1,217 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to conjunctive phenomena or (rule 2) +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to analyse conjunctive phenomena (or) +# Rule: property(property, or_phenomena) => compositeProperty +#============================================================================== + +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_composite_naming_1, define_restriction_naming + + +#============================================================================== +# Search for patterns: property(property, or_phenomena) +#============================================================================== + +def __rule_pattern_query_code(graph): + select_data_list = ['?property_net_core', '?property_net_arg0', '?phenomena_net'] + clause_list = [] + clause_list.append(f'?property_net_core a [rdfs:subClassOf* net:Property_Net].') + clause_list.append(f'?property_net_arg0 a [rdfs:subClassOf* net:Property_Net].') + clause_list.append(f'?phenomena_net a [rdfs:subClassOf* net:Phenomena_Net].') + clause_list.append(f'?phenomena_net net:hasPhenomenaType amr:phenomena_conjunction_or.') + clause_list.append(f'?property_net_core amr:role_ARG0 ?property_net_arg0.') + clause_list.append(f'?property_net_core amr:role_ARG1 ?phenomena_net.') + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_pattern(graph): + query_code = __rule_pattern_query_code(graph) + rule_pattern_set = graph.query(query_code) + return rule_pattern_set + + + +#============================================================================== +# Search for phenomena operators: +#============================================================================== + +def __property_op_pattern_query_code(graph, phenomena_net_uri, num): + assert 1 <= num <= 9, f'invalid number ({num})' + select_data_list = ['?property_net'] + clause_list = [f'?property_net a [rdfs:subClassOf* net:Property_Net].'] + clause_list.append((phenomena_net_uri, f'amr:role_op{num}', '?property_net')) + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_property_phenomena_operator(graph, phenomena_net_uri): + op_set = [] + for num in range(1, 9+1): + query_code = __property_op_pattern_query_code(graph, phenomena_net_uri, num) + op_set += graph.query(query_code) + return op_set + + + +#============================================================================== +# Relation Propagation +#============================================================================== + +def __filter_relation(relation_list): + result_list = [] + for relation in relation_list: + check = True + (s, p, o) = relation + if s == o: check = False + if check: result_list.append(relation) + return result_list + + +def __propagate_relation(target_net, base_net): + # -- target_net.input_relation_list = base_net.input_relation_list + out_relation_list = __filter_relation(base_net.output_relation_list) + target_net.output_relation_list = out_relation_list + + + +#============================================================================== +# Construct Methods: construction of composite property net +#============================================================================== + +def __construct_restriction_net(graph, property_net_1, property_net_2): + + restriction_net = net.RestrictionNet(graph) + restriction_net.compose(property_net_1, property_net_2) + + # -- Data Computation + restriction_net.restriction_property = property_net_1.uri + restriction_net.restriction_net_value = property_net_2.uri + + # -- Relation Propagation: None + + # -- Net Naming + restriction_net.naming = define_restriction_naming(property_net_1, property_net_2) + + # -- Finalization + restriction_net.finalize() + triple_list = restriction_net.generate_triple_definition() + + return restriction_net, triple_list + + + +def __construct_composite_property_net_from_3_properties( + graph, base_property_net, core_property_net, target_property_net): + + # -- Net Composition + composite_property_net = net.CompositePropertyNet(graph) + composite_property_net.compose(base_property_net, core_property_net, target_property_net) + + # -- Data Computation + composite_property_net.mother_property_net = base_property_net.uri + composite_property_net.property_type = 'owl:ObjectProperty' + + # -- Restriction Computation + restriction_net, triple_list_1 = __construct_restriction_net(graph, core_property_net, target_property_net) + composite_property_net.restriction = restriction_net.uri + + # -- Relation Propagation + __propagate_relation(composite_property_net, base_property_net) + + # -- Net Naming + composite_property_net.naming = define_composite_naming_1( + base_property_net, core_property_net, target_property_net) + + # -- Finalization + composite_property_net.finalize() + triple_list_2 = composite_property_net.generate_triple_definition() + result_triple_list = triple_list_1 + triple_list_2 + + return composite_property_net, result_triple_list + + + +def __construct_property_union_net(graph, base_property_net, property_net_list): + + # -- Net Composition + property_union_net = net.PropertyUnionNet(graph) + property_union_net.compose(base_property_net, property_net_list) + + # -- Data Computation: None + + # -- Restriction Computation: None + + # -- Relation Propagation + __propagate_relation(property_union_net, base_property_net) + + # -- Net Naming + property_union_net.naming = define_union_naming(base_property_net) + + # -- Finalization + property_union_net.finalize() + triple_list = property_union_net.generate_triple_definition() + + return property_union_net, triple_list + + + +#============================================================================== +# Main Method: analyze_phenomena_or_2 +#============================================================================== + +def analyze_phenomena_or_2(graph): + + # -- Rule Initialization + rule_label = 'analyze "or" phenomena (2)' + # print(f"--- *** February Transduction *** Sequence: {rule_label}") + + # -- Search for patterns + rule_pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for selection_1 in rule_pattern_set: + + # -- Net Selection + property_net_1 = net.PropertyNet(graph, uri=selection_1.property_net_arg0) + property_net_2 = net.PropertyNet(graph, uri=selection_1.property_net_core) + phenomena_net = net.PhenomenaNet(graph, uri=selection_1.phenomena_net) + + # -- Search for phenomena operators + property_operator_set = __search_property_phenomena_operator(graph, phenomena_net.uri) + + # -- Selection Analyzing (2) + property_net_list = [] + for selection_2 in property_operator_set: + # print(f' *** DEVTEST *** {selection_2.property_net}') + + # -- Net Selection + property_net_3 = net.PropertyNet(graph, uri=selection_2.property_net) + + # -- New Net Construction (from 3 property nets) + new_property, triple_list = __construct_composite_property_net_from_3_properties( + graph, property_net_1, property_net_2, property_net_3) + + # -- Resulting List Update + property_net_list.append(new_property) + rule_triple_list += triple_list + + # -- Deprecation: Origin Property Net + rule_triple_list += property_net_1.deprecate() + + # -- New Net Construction (as union of properties) + # _, triple_list = __construct_property_union_net(graph, property_net_1, property_net_list) + # rule_triple_list += triple_list + + return rule_label, rule_triple_list + + \ No newline at end of file diff --git a/tenet/scheme/amr_master_rule/transduction/phenomena_polarity_analyzer_1.py b/tenet/scheme/amr_master_rule/transduction/phenomena_polarity_analyzer_1.py new file mode 100644 index 0000000000000000000000000000000000000000..2abc287c655f4c1fc86b8d62a20d8fca24b5067d --- /dev/null +++ b/tenet/scheme/amr_master_rule/transduction/phenomena_polarity_analyzer_1.py @@ -0,0 +1,155 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Rule to conjunctive phenomena or (rule 1) +#------------------------------------------------------------------------------ +# Net Expansion AMR rule to analyse conjunctive phenomena (or) +# Rule: property(class, or_phenomena) => compositeClass +#============================================================================== + +import rdflib +from rdflib import Graph + +import transduction +from transduction import net +from transduction.query_builder import generate_select_query +from transduction.naming_computer import define_axiom_naming +from transduction.naming_computer import define_composite_naming_2 + + +#============================================================================== +# Select Pattern: polarity(property, 'negative') +#============================================================================== + +POLARITY_RELATION = 'amr:role_polarity' + +def __rule_pattern_query_code(graph): + select_data_list = ['?property_net'] + clause_list = [] + clause_list.append(f'?property_net a [rdfs:subClassOf* net:Property_Net].') + clause_list.append(f'?property_net {POLARITY_RELATION} ?value_net.') + clause_list.append(('?value_net', 'net:hasValueLabel', rdflib.term.Literal('negative'))) + query_code = generate_select_query(graph, select_data_list, clause_list) + return query_code + + +def __search_pattern(graph): + query_code = __rule_pattern_query_code(graph) + rule_pattern_set = graph.query(query_code) + return rule_pattern_set + + + +#============================================================================== +# Relation Propagation +#============================================================================== + +def __filter_relation(relation_list): + result_list = [] + for relation in relation_list: + check = True + (s, p, o) = relation + if s == o: check = False + if p == POLARITY_RELATION: check = False + if check: result_list.append(relation) + return result_list + + +def __propagate_relation(target_net, base_net): + target_net.input_relation_list = base_net.input_relation_list + out_relation_list = __filter_relation(base_net.output_relation_list) + target_net.output_relation_list = out_relation_list + + + +#============================================================================== +# Construct Methods: construction of composite class net +#============================================================================== + +def __construct_disjoint_axiom_net(graph, property_net_1, property_net_2): + + axiom_net = net.AxiomNet(graph) + axiom_net.compose(property_net_1, property_net_2) + + # -- Data Computation + axiom_net.axiom_name = 'disjointProperty' + axiom_net.axiom_uri = 'owl:propertyDisjointWith' + axiom_net.axiom_net_argument = [property_net_1.uri, property_net_2.uri] + + # -- Relation Propagation: None + + # -- Net Naming + arg_net_list = [property_net_1, property_net_2] + axiom_net.naming = define_axiom_naming(axiom_net, arg_net_list) + + # -- Finalization + axiom_net.finalize() + triple_list = axiom_net.generate_triple_definition() + + return axiom_net, triple_list + + + +def __construct_negative_property_net(graph, property_net_1): + + # -- Net Composition + composite_property_net = net.CompositePropertyNet(graph) + composite_property_net.compose(property_net_1) + + # -- Data Computation + composite_property_net.property_type = 'owl:ObjectProperty' + + # -- Restriction Computation + triple_list_1 = [] + # restriction_net, triple_list_1 = __construct_restriction_net(graph, property_net_1) + # composite_class_net.restriction = restriction_net.uri + + # -- Relation Propagation + __propagate_relation(composite_property_net, property_net_1) + + # -- Net Naming + composite_property_net.naming = define_composite_naming_2('not', property_net_1) + + # -- Finalization + composite_property_net.finalize() + triple_list_2 = composite_property_net.generate_triple_definition() + result_triple_list = triple_list_1 + triple_list_2 + + return composite_property_net, result_triple_list + + + +#============================================================================== +# Main Method: analyze_phenomena_or_1 +#============================================================================== + +def analyze_phenomena_polarity_1(graph): + + # -- Rule Initialization + rule_label = 'analyze "polarity" phenomena' + + # -- Search for patterns + rule_pattern_set = __search_pattern(graph) + + # -- Selection Analyzing (1) + rule_triple_list = [] + for selection_1 in rule_pattern_set: + + # -- Net Selection + property_net = net.PropertyNet(graph, uri=selection_1.property_net) + + # -- New Negative Property Net + negative_property_net, triple_list_1 = __construct_negative_property_net(graph, property_net) + + # -- New Axiom Net + _, triple_list_2 = __construct_disjoint_axiom_net(graph, property_net, negative_property_net) + _, triple_list_3 = __construct_disjoint_axiom_net(graph, negative_property_net, property_net) + + # -- Update Rule Triple List + rule_triple_list += triple_list_1 + triple_list_2 + triple_list_3 + + # -- Deprecation: Origin Class Net + rule_triple_list += property_net.deprecate() + + return rule_label, rule_triple_list \ No newline at end of file diff --git a/tenet/scheme/amr_rule/__init__.py b/tenet/scheme/amr_rule/__init__.py deleted file mode 100644 index 15cf9879996760c5c98b664236fa564c71092379..0000000000000000000000000000000000000000 --- a/tenet/scheme/amr_rule/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -from scheme.amr_rule.preprocessing.amr_reification import * -from scheme.amr_rule.preprocessing.amrld_correcting import * - -from scheme.amr_rule.transduction.atom_class_extractor import * -from scheme.amr_rule.transduction.atom_individual_extractor import * -from scheme.amr_rule.transduction.atom_property_extractor import * -from scheme.amr_rule.transduction.atom_value_extractor import * -from scheme.amr_rule.transduction.atom_phenomena_extractor import * -from scheme.amr_rule.transduction.atom_relation_propagator import * - -from scheme.amr_rule.transduction.composite_class_extractor_1 import * -from scheme.amr_rule.transduction.composite_class_extractor_2 import * - -from scheme.amr_rule.transduction.phenomena_polarity_analyzer_1 import * -from scheme.amr_rule.transduction.phenomena_mod_analyzer_1 import * -from scheme.amr_rule.transduction.phenomena_or_analyzer_1 import * -from scheme.amr_rule.transduction.phenomena_or_analyzer_2 import * - -from scheme.amr_rule.generation.owl_property_generator import * - -from scheme.amr_rule import * diff --git a/tenet/scheme/amr_scheme_clara_1.py b/tenet/scheme/amr_scheme_clara_1.py new file mode 100644 index 0000000000000000000000000000000000000000..7e9812d5505368300e8694940090d7dafd60687e --- /dev/null +++ b/tenet/scheme/amr_scheme_clara_1.py @@ -0,0 +1,234 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Composition Transduction Scheme for AMR analysis +#------------------------------------------------------------------------------ +# Composition Transduction Scheme (CTS) using CTR (rules) for analysis of AMR +# structure. +#============================================================================== + +import scheme.amr_clara_rule as rule + +#============================================================================== +# Rule Directory +#============================================================================== + +rule_dir = 'amr_clara_rule/' + + +#============================================================================== +# Prefix using in CTR +#============================================================================== + +prefix_list = [('owl', '<http://www.w3.org/2002/07/owl#>'), + ('rdf', '<http://www.w3.org/1999/02/22-rdf-syntax-ns#>'), + ('rdfs', '<http://www.w3.org/2000/01/rdf-schema#>'), + ('xsd', '<http://www.w3.org/2001/XMLSchema#>'), + ('amr', '<https://amr.tetras-libre.fr/rdf/schema#>'), + ('ns1', '<http://amr.isi.edu/frames/ld/v1.2.2/>'), + ('ns2', '<http://amr.isi.edu/rdf/amr-terms#>'), + ('ns3', '<http://amr.isi.edu/rdf/core-amr#>'), + ('ns4', '<http://amr.isi.edu/entity-types#>'), + ('net', '<https://tenet.tetras-libre.fr/semantic-net#>'), + ('cprm', '<https://tenet.tetras-libre.fr/config/parameters#>'), + ('fprm', '<https://tenet.tetras-libre.fr/frame/parameters#>'), + ('base-out', '<https://tenet.tetras-libre.fr/base-ontology#>'), + ('ext-out', '<https://tenet.tetras-libre.fr/extract-result#>')] + + +#============================================================================== +# Sequences +#============================================================================== + +# --------------------------------------------- +# Refinement Sequence(s) +# --------------------------------------------- + +default_refinement_sequence = { + 'label': 'default-refinement-sequence', + 'comment': 'sequence without rule', + 'rule_key_list': [] + } + +transduction_refinement_sequence = { + 'label': 'transduction-refinement-sequence', + 'comment': 'Refinement Sequence for Transduction Processing', + 'rule_key_list': ['refine-cover-node-1', + 'refine-cover-node-2']#, + #'propagation-relations-to-nets'] + } + + +# --------------------------------------------- +# Preprocessing Sequence(s) +# --------------------------------------------- + +amrld_correcting_sequence = { + 'label': 'amrld-correcting-sequence', + 'comment': 'correction of AMR-LD data for some known anomalies', + 'rule_key_list': ['fix-amr-bug-about-system-solar-planet'] + } + +amr_reification_sequence = { + 'label': 'amr-reification-sequence', + 'comment': 'AMR reification from AMR-Linked-Data to AMR (tenet) structure', + 'rule_key_list': ['reclassify-concept-1', + 'reclassify-concept-2', + 'reclassify-concept-3', + 'reclassify-concept-4', + 'reclassify-concept-5', + # --old --- 'reclassify-role-1', + # --old --- 'reclassify-role-2', + 'reify-roles-as-concept', + 'reclassify-existing-variable', + 'add-new-variable-for-reified-concept', + 'add-amr-leaf-for-reclassified-concept', + 'add-amr-leaf-for-reified-concept', + 'add-amr-edge-for-core-relation', + 'add-amr-edge-for-reified-concept', + 'add-amr-edge-for-name-relation', + 'add-amr-edge-for-quant-relation', + 'add-amr-edge-for-polarity-relation', + # --old --- 'set-amr-label-for-variables', + # --old --- 'set-amr-label-for-roles', + 'update-amr-edge-role-1', + # --old --- 'update-amr-edge-role-2', + 'add-amr-root'] + } + + +# # --------------------------------------------- +# # Transduction Sequences +# # --------------------------------------------- + +phenomena_application_and_sequence = { + 'label': 'phenomena-application-and-sequence', + 'comment': 'Application of phenomena', + 'rule_key_list': ['and-conjunction-phenomena-application-1', + 'and-conjunction-phenomena-application-2', + 'and-conjunction-phenomena-application-3', + 'and-conjunction-phenomena-application-4', + 'and-conjunction-phenomena-application-5', + 'and-conjunction-phenomena-application-6' + ] + } + + +composite_property_extraction_sequence = { + 'label': 'composite-property-extraction-sequence', + 'comment': 'creation of composite properties from properties', + 'rule_key_list': ['create-composite-property-net-from-property-1', + 'create-composite-property-net-from-property-2'] + } + + +restriction_adding_sequence = { + 'label': 'restriction-adding-sequence', + 'comment': 'add restriction to class from property', + 'rule_key_list': ['add-restriction-to-class-net-from-property-1'] + } + + +phenomena_checking_sequence = { + 'label': 'phenomena-checking-sequence', + 'comment': 'creation of phenomena nets', + 'rule_key_list': ['expand-and-or-conjunction-phenomena-net', + 'expand-degree-phenomena-net-1', + 'expand-degree-phenomena-net-2', + 'expand-degree-phenomena-net-3', + 'expand-degree-phenomena-net-4', + 'expand-degree-phenomena-net-5', + 'expand-degree-phenomena-net-6'] + } + + +composite_class_extraction_sequence_2 = { + 'label': 'composite-class-extraction-sequence-2', + 'comment': 'creation of composite classes from phenomena', + 'rule_key_list': ['create-composite-class-net-from-phenomena-1', + 'create-composite-class-net-from-phenomena-2', + 'create-composite-class-net-from-phenomena-3', + 'create-composite-class-net-from-phenomena-4'] + } + + +classification_sequence = { + 'label': 'classification-sequence', + 'comment': 'net classification', + 'rule_key_list': ['classify-net-from-core-1', + 'classify-net-from-core-2', + 'classify-net-from-core-3', + # -- old --- 'classify-net-from-mod', + 'classify-net-from-part', + 'classify-net-from-domain', + 'classify-net-from-degree-phenomena-1', + 'classify-net-from-degree-phenomena-2', + 'classify-net-from-degree-phenomena-3', + 'propagate-individual-1', + 'propagate-individual-2', + 'reclassify-deprecated-net'] + } + +atomic_extraction_sequence = ['atomic extraction sequence', + rule.extract_atom_class, + rule.extract_atom_individual, + rule.extract_atom_property, + rule.extract_atom_value, + rule.extract_atom_phenomena, + rule.propagate_atom_relation] + +phenomena_analyze_sequence_1 = ['phenomena analyze sequence (1)', + rule.analyze_phenomena_polarity_1, + rule.analyze_phenomena_mod_1 + ] + +phenomena_analyze_sequence_2 = ['phenomena analyze sequence (2)', + rule.analyze_phenomena_or_1, + rule.analyze_phenomena_or_2] + +composite_class_extraction_sequence = ['composite class extraction sequence', + rule.extract_composite_class_1, + rule.extract_composite_class_2] + + +# # --------------------------------------------- +# # ODRL Generation +# # --------------------------------------------- + +odrl_rule_generation_sequence = ['ODRL Rule Generation Sequence', + rule.generate_odrl_rule] + + + +#============================================================================== +# Transduction Scheme +#============================================================================== + +scheme = { + + 'preprocessing': [default_refinement_sequence, + amrld_correcting_sequence, + amr_reification_sequence], + + 'transduction': [transduction_refinement_sequence, + atomic_extraction_sequence, + phenomena_analyze_sequence_1, + phenomena_analyze_sequence_2, + composite_class_extraction_sequence, + ], + + # 'transduction': [transduction_refinement_sequence, + # phenomena_application_and_sequence, + # phenomena_checking_sequence, + # composite_property_extraction_sequence, + # composite_class_extraction_sequence_2, + # restriction_adding_sequence, + # classification_sequence], + + 'generation': [default_refinement_sequence, + odrl_rule_generation_sequence] + + } + + diff --git a/tenet/scheme/amr_scheme_1.py b/tenet/scheme/amr_scheme_master_1.py similarity index 99% rename from tenet/scheme/amr_scheme_1.py rename to tenet/scheme/amr_scheme_master_1.py index b7f390120a628bd926a9fe11f7f3d2c86dc4dd49..18f90f84682817fce27f2774cd4db9259f662729 100644 --- a/tenet/scheme/amr_scheme_1.py +++ b/tenet/scheme/amr_scheme_master_1.py @@ -8,13 +8,13 @@ # structure. #============================================================================== -import scheme.amr_rule as rule +import scheme.amr_master_rule as rule #============================================================================== # Rule Directory #============================================================================== -rule_dir = 'amr_rule/' +rule_dir = 'amr_master_rule/' #============================================================================== diff --git a/tenet/scheme/unl_rule/old_unl_ctr.py b/tenet/scheme/unl_old_rule/old_unl_ctr.py similarity index 100% rename from tenet/scheme/unl_rule/old_unl_ctr.py rename to tenet/scheme/unl_old_rule/old_unl_ctr.py diff --git a/tenet/scheme/unl_rule/unl_ctr_data_preprocessing.py b/tenet/scheme/unl_old_rule/unl_ctr_data_preprocessing.py similarity index 100% rename from tenet/scheme/unl_rule/unl_ctr_data_preprocessing.py rename to tenet/scheme/unl_old_rule/unl_ctr_data_preprocessing.py diff --git a/tenet/scheme/unl_rule/unl_ctr_net_expansion.py b/tenet/scheme/unl_old_rule/unl_ctr_net_expansion.py similarity index 100% rename from tenet/scheme/unl_rule/unl_ctr_net_expansion.py rename to tenet/scheme/unl_old_rule/unl_ctr_net_expansion.py diff --git a/tenet/scheme/unl_rule/unl_ctr_owl_generation.py b/tenet/scheme/unl_old_rule/unl_ctr_owl_generation.py similarity index 100% rename from tenet/scheme/unl_rule/unl_ctr_owl_generation.py rename to tenet/scheme/unl_old_rule/unl_ctr_owl_generation.py diff --git a/tenet/scheme/unl_rule/unl_ctr_test.py b/tenet/scheme/unl_old_rule/unl_ctr_test.py similarity index 100% rename from tenet/scheme/unl_rule/unl_ctr_test.py rename to tenet/scheme/unl_old_rule/unl_ctr_test.py diff --git a/tenet/structure/amr-rdf-schema.ttl b/tenet/structure/amr-rdf-schema.ttl index 39f74f9490188364dda009040c6a6e47262624ac..5b102697ec90857408d83d2d9cf64ccdce278345 100644 --- a/tenet/structure/amr-rdf-schema.ttl +++ b/tenet/structure/amr-rdf-schema.ttl @@ -373,6 +373,25 @@ ns1:Role rdf:type owl:Class ; :label "degree" . +### https://amr.tetras-libre.fr/rdf/schema#phenomena_modality +:phenomena_modality rdf:type owl:Class ; + rdfs:subClassOf :AMR_Phenomena . + + +### https://amr.tetras-libre.fr/rdf/schema#phenomena_modality_obligation +:phenomena_modality_obligation rdf:type owl:Class ; + rdfs:subClassOf :phenomena_modality ; + :hasConceptLink "obligate-01" ; + :label "obligation-modality" . + + +### https://amr.tetras-libre.fr/rdf/schema#phenomena_modality_possible +:phenomena_modality_possible rdf:type owl:Class ; + rdfs:subClassOf :phenomena_modality ; + :hasConceptLink "possible-01", "permit-01", "likely-01", "grant-01" ; + :label "possible-modality" . + + ### https://amr.tetras-libre.fr/rdf/schema#relation_domain :relation_domain rdf:type owl:Class ; rdfs:subClassOf :AMR_Relation ; diff --git a/tenet/structure/odrl-snet-schema.ttl b/tenet/structure/odrl-snet-schema.ttl new file mode 100644 index 0000000000000000000000000000000000000000..998691874b5541ad9d83020b5e570bbfcabc2c04 --- /dev/null +++ b/tenet/structure/odrl-snet-schema.ttl @@ -0,0 +1,366 @@ +@prefix : <https://tenet.tetras-libre.fr/semantic-net#> . +@prefix net: <https://tenet.tetras-libre.fr/semantic-net#> . +@prefix owl: <http://www.w3.org/2002/07/owl#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix xml: <http://www.w3.org/XML/1998/namespace> . +@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . +@base <https://tenet.tetras-libre.fr/semantic-net> . + +<https://tenet.tetras-libre.fr/semantic-net> rdf:type owl:Ontology . + +################################################################# +# Annotation properties +################################################################# + +### https://tenet.tetras-libre.fr/semantic-net#abstractionClass +net:abstractionClass rdf:type owl:AnnotationProperty ; + rdfs:label "abstraction class" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#atomOf +net:atomOf rdf:type owl:AnnotationProperty ; + rdfs:label "atom of" ; + rdfs:subPropertyOf net:typeProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#atomType +net:atomType rdf:type owl:AnnotationProperty ; + rdfs:label "atom type" ; + rdfs:subPropertyOf net:objectType . + + +### https://tenet.tetras-libre.fr/semantic-net#entityClass +net:entityClass rdf:type owl:AnnotationProperty ; + rdfs:label "entity class" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#featureClass +net:featureClass rdf:type owl:AnnotationProperty ; + rdfs:label "feature class" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_atom +net:has_atom rdf:type owl:AnnotationProperty ; + rdfs:label "has atom" ; + rdfs:subPropertyOf net:has_object . + + +### https://tenet.tetras-libre.fr/semantic-net#has_class +net:has_class rdf:type owl:AnnotationProperty ; + rdfs:label "is class" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_class_name +net:has_class_name rdf:type owl:AnnotationProperty ; + rdfs:subPropertyOf net:has_value . + + +### https://tenet.tetras-libre.fr/semantic-net#has_class_uri +net:has_class_uri rdf:type owl:AnnotationProperty ; + rdfs:label "class uri" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_concept +net:has_concept rdf:type owl:AnnotationProperty ; + rdfs:label "concept "@fr ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_entity +net:has_entity rdf:type owl:AnnotationProperty ; + rdfs:label "has entity" ; + rdfs:subPropertyOf net:has_object . + + +### https://tenet.tetras-libre.fr/semantic-net#has_feature +net:has_feature rdf:type owl:AnnotationProperty ; + rdfs:label "has feature" ; + rdfs:subPropertyOf net:has_object . + + +### https://tenet.tetras-libre.fr/semantic-net#has_instance +net:has_instance rdf:type owl:AnnotationProperty ; + rdfs:label "entity instance" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_instance_uri +net:has_instance_uri rdf:type owl:AnnotationProperty ; + rdfs:label "instance uri" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_item +net:has_item rdf:type owl:AnnotationProperty ; + rdfs:label "has item" ; + rdfs:subPropertyOf net:has_object . + + +### https://tenet.tetras-libre.fr/semantic-net#has_mother_class +net:has_mother_class rdf:type owl:AnnotationProperty ; + rdfs:label "has mother class" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_mother_class_uri +net:has_mother_class_uri rdf:type owl:AnnotationProperty ; + rdfs:label "parent class uri" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_node +net:has_node rdf:type owl:AnnotationProperty ; + rdfs:label "UNL Node" ; + rdfs:subPropertyOf net:netProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#has_object +net:has_object rdf:type owl:AnnotationProperty ; + rdfs:label "relation" ; + rdfs:subPropertyOf net:netProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#has_parent +net:has_parent rdf:type owl:AnnotationProperty ; + rdfs:label "has parent" ; + rdfs:subPropertyOf net:has_object . + + +### https://tenet.tetras-libre.fr/semantic-net#has_parent_class +net:has_parent_class rdf:type owl:AnnotationProperty ; + rdfs:label "parent class" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_parent_class_uri +net:has_parent_class_uri rdf:type owl:AnnotationProperty ; + rdfs:label "parent class uri" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#has_possible_domain +net:has_possible_domain rdf:type owl:AnnotationProperty ; + rdfs:label "has possible domain" ; + rdfs:subPropertyOf net:has_object . + + +### https://tenet.tetras-libre.fr/semantic-net#has_possible_range +net:has_possible_range rdf:type owl:AnnotationProperty ; + rdfs:label "has possible range" ; + rdfs:subPropertyOf net:has_object . + + +### https://tenet.tetras-libre.fr/semantic-net#has_relation +net:has_relation rdf:type owl:AnnotationProperty ; + rdfs:label "has relation" ; + rdfs:subPropertyOf net:has_relation_value . + + +### https://tenet.tetras-libre.fr/semantic-net#has_relation_value +net:has_relation_value rdf:type owl:AnnotationProperty ; + rdfs:label "has relation value" ; + rdfs:subPropertyOf net:has_object . + + +### https://tenet.tetras-libre.fr/semantic-net#has_source +net:has_source rdf:type owl:AnnotationProperty ; + rdfs:label "has source" ; + rdfs:subPropertyOf net:has_relation_value . + + +### https://tenet.tetras-libre.fr/semantic-net#has_structure +net:has_structure rdf:type owl:AnnotationProperty ; + rdfs:label "Linguistic Structure (in UNL Document)" ; + rdfs:subPropertyOf net:netProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#has_target +net:has_target rdf:type owl:AnnotationProperty ; + rdfs:label "has target" ; + rdfs:subPropertyOf net:has_relation_value . + + +### https://tenet.tetras-libre.fr/semantic-net#has_value +net:has_value rdf:type owl:AnnotationProperty ; + rdfs:subPropertyOf net:netProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#listBy +net:listBy rdf:type owl:AnnotationProperty ; + rdfs:label "list by" ; + rdfs:subPropertyOf net:typeProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#listGuiding +net:listGuiding rdf:type owl:AnnotationProperty ; + rdfs:label "Guiding connector of a list (or, and)" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#listOf +net:listOf rdf:type owl:AnnotationProperty ; + rdfs:label "list of" ; + rdfs:subPropertyOf net:typeProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#modCat1 +net:modCat1 rdf:type owl:AnnotationProperty ; + rdfs:label "Modality Category (level 1)" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#modCat2 +net:modCat2 rdf:type owl:AnnotationProperty ; + rdfs:label "Modality Category (level 2)" ; + rdfs:subPropertyOf net:objectValue . + + +### https://tenet.tetras-libre.fr/semantic-net#netProperty +net:netProperty rdf:type owl:AnnotationProperty ; + rdfs:label "netProperty" . + + +### https://tenet.tetras-libre.fr/semantic-net#objectProperty +net:objectProperty rdf:type owl:AnnotationProperty ; + rdfs:label "object attribute" . + + +### https://tenet.tetras-libre.fr/semantic-net#objectType +net:objectType rdf:type owl:AnnotationProperty ; + rdfs:label "object type" ; + rdfs:subPropertyOf net:objectProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#objectValue +net:objectValue rdf:type owl:AnnotationProperty ; + rdfs:label "valuations"@fr ; + rdfs:subPropertyOf net:objectProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#relationOf +net:relationOf rdf:type owl:AnnotationProperty ; + rdfs:label "relation of" ; + rdfs:subPropertyOf net:typeProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#type +net:type rdf:type owl:AnnotationProperty ; + rdfs:label "type "@fr ; + rdfs:subPropertyOf net:netProperty . + + +### https://tenet.tetras-libre.fr/semantic-net#typeProperty +net:typeProperty rdf:type owl:AnnotationProperty ; + rdfs:label "type property" . + + +### https://tenet.tetras-libre.fr/semantic-net#verbClass +net:verbClass rdf:type owl:AnnotationProperty ; + rdfs:label "verb class" ; + rdfs:subPropertyOf net:objectValue . + + +################################################################# +# Classes +################################################################# + +### https://tenet.tetras-libre.fr/semantic-net#Action_Net +net:Action_Net rdf:type owl:Class ; + rdfs:subClassOf net:Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Atom_Class_Net +net:Atom_Class_Net rdf:type owl:Class ; + rdfs:subClassOf net:Class_Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Atom_Property_Net +net:Atom_Property_Net rdf:type owl:Class ; + rdfs:subClassOf net:Property_Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Class_Net +net:Class_Net rdf:type owl:Class ; + rdfs:subClassOf net:Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Composite_Class_Net +net:Composite_Class_Net rdf:type owl:Class ; + rdfs:subClassOf net:Class_Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Composite_Property_Net +net:Composite_Property_Net rdf:type owl:Class ; + rdfs:subClassOf net:Property_Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Deprecated_Net +net:Deprecated_Net rdf:type owl:Class ; + rdfs:subClassOf net:Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Feature +net:Feature rdf:type owl:Class ; + rdfs:subClassOf net:Net_Structure . + + +### https://tenet.tetras-libre.fr/semantic-net#Individual_Net +net:Individual_Net rdf:type owl:Class ; + rdfs:subClassOf net:Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Net +net:Net rdf:type owl:Class ; + rdfs:subClassOf net:Net_Structure . + + +### https://tenet.tetras-libre.fr/semantic-net#Net_Structure +net:Net_Structure rdf:type owl:Class ; + rdfs:comment "A semantic net captures a set of nodes, and associates this set with type(s) and value(s)." ; + rdfs:label "Semantic Net Structure" . + + +### https://tenet.tetras-libre.fr/semantic-net#Phenomena_Net +net:Phenomena_Net rdf:type owl:Class ; + rdfs:subClassOf net:Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Property_Net +net:Property_Net rdf:type owl:Class ; + rdfs:subClassOf net:Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Relation +net:Relation rdf:type owl:Class ; + rdfs:subClassOf net:Net_Structure . + + +### https://tenet.tetras-libre.fr/semantic-net#Rule_Net +net:Rule_Net rdf:type owl:Class ; + rdfs:subClassOf net:Net . + + +### https://tenet.tetras-libre.fr/semantic-net#Value_Net +net:Value_Net rdf:type owl:Class ; + rdfs:subClassOf net:Net . + + +################################################################# +# Individuals +################################################################# + +### https://tenet.tetras-libre.fr/semantic-net#inverse_direction +net:inverse_direction rdf:type owl:NamedIndividual . + + +### https://tenet.tetras-libre.fr/semantic-net#normal_direction +net:normal_direction rdf:type owl:NamedIndividual . + + +### Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi diff --git a/tenet/structure/semantic-net.ttl b/tenet/structure/owl-snet-schema.ttl similarity index 100% rename from tenet/structure/semantic-net.ttl rename to tenet/structure/owl-snet-schema.ttl diff --git a/tenet/tenet.log b/tenet/tenet.log index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f0f2598fbe69e0c8f12b4b868e1b3f3cf3aff6a1 100644 --- a/tenet/tenet.log +++ b/tenet/tenet.log @@ -0,0 +1,151 @@ +- INFO - [TENET] Extraction Processing +- INFO - + === Process Initialization === +- INFO - -- Process Setting +- INFO - ----- Corpus source: /home/lamenji/Workspace/Tetras/tenet/tests/input/amrDocuments/dev/asail_odrl_sentences/s01.stog.amr.ttl (amr) +- INFO - ----- Base output dir: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/aos01_factoid.ttl +- INFO - ----- technical dir path: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/technical-data/ +- INFO - ----- Ontology target (id): https://tenet.tetras-libre.fr/demo/clara/01/ +- INFO - ----- Current path: /home/lamenji/Workspace/Tetras/tenet/tenet +- DEBUG - ----- Config file: /home/lamenji/Workspace/Tetras/tenet/tenet/config.xml +- DEBUG - + *** Config (Full Parameters) *** + -- Base Parameters + ----- config file: /home/lamenji/Workspace/Tetras/tenet/tenet/config.xml + ----- uuid: https://tenet.tetras-libre.fr/demo/clara/01/ + ----- technical base name: tenet.tetras-libre.fr_demo_clara_01 + ----- source corpus: /home/lamenji/Workspace/Tetras/tenet/tests/input/amrDocuments/dev/asail_odrl_sentences/s01.stog.amr.ttl + ----- target reference: base + ----- process level: sentence + ----- source type: amr + -- Compositional Transduction Scheme (CTS) + ----- CTS reference: amr_scheme_clara_1 + -- Directories + ----- base directory: ./ + ----- structure directory: ./structure/ + ----- CTS directory: ./scheme/ + ----- target frame directory: ./../input/targetFrameStructure/ + ----- input document directory: + ----- base output dir: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/aos01_factoid.ttl + ----- output directory: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/aos01_factoid.ttltenet.tetras-libre.fr_demo_clara_01-20230411/ + ----- sentence output directory: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/technical-data/ + ----- technical dir path: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/technical-data/ + -- Config File Definition + ----- schema file: ./structure/amr-rdf-schema.ttl + ----- semantic net file: ./structure/odrl-snet-schema.ttl + ----- config param file: ./structure/config-parameters.ttl + ----- base ontology file: ./structure/base-ontology.ttl + ----- CTS file: ./scheme/amr_scheme_clara_1.py + -- Useful References for Ontology + ----- base URI: https://tenet.tetras-libre.fr/working + ----- ontology suffix: -ontology.ttl + ----- ontology seed suffix: -ontology-seed.ttl + -- Source File Definition + ----- source sentence file: /home/lamenji/Workspace/Tetras/tenet/tests/input/amrDocuments/dev/asail_odrl_sentences/s01.stog.amr.ttl**/*.ttl + -- Target File Definition + ----- frame ontology file: ./../input/targetFrameStructure/base-ontology.ttl + ----- frame ontology seed file: ./../input/targetFrameStructure/base-ontology-seed.ttl + -- Output + ----- ontology namespace: https://tenet.tetras-libre.fr/base-ontology/ + ----- output file: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/technical-data/tenet.tetras-libre.fr_demo_clara_01.ttl + *** - *** +- INFO - + === Extraction Processing === +- INFO - -- Work Structure Preparation +- DEBUG - --- Graph Initialization +- DEBUG - ----- Configuration Loading +- DEBUG - -------- RDF Schema (315) +- DEBUG - -------- Semantic Net Definition (475) +- DEBUG - -------- Config Parameter Definition (509) +- DEBUG - ----- Frame Ontology Loading +- DEBUG - -------- Base Ontology produced as output (539) +- DEBUG - --- Source Data Import +- DEBUG - ----- Sentence Loading +- DEBUG - -------- /home/lamenji/Workspace/Tetras/tenet/tests/input/amrDocuments/dev/asail_odrl_sentences/s01.stog.amr.ttl (556) +- DEBUG - --- Export work graph as turtle +- DEBUG - ----- Work graph file: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/technical-data/tenet.tetras-libre.fr_demo_clara_01-0/tenet.tetras-libre.fr_demo_clara_01.ttl +- INFO - ----- Sentence (id): document-01 +- INFO - ----- Sentence (text): Movie9898 can be used. +- INFO - -- Loading Extraction Scheme (amr_scheme_clara_1) +- DEBUG - ----- Step number: 3 +- INFO - -- Loading Extraction Rules (amr_clara_rule/*) +- DEBUG - ----- Total rule number: 87 +- INFO - -- Applying extraction step: preprocessing +- INFO - --- *** November Transduction *** Sequence: amrld-correcting-sequence +- DEBUG - ----- fix-amr-bug-about-system-solar-planet: 0/0 new triple (556, 0:00:00.036256) +- INFO - --- *** November Transduction *** Sequence: amr-reification-sequence +- INFO - ----- reclassify-concept-1: 5/5 new triples (561, 0:00:00.138418) +- DEBUG - ----- reclassify-concept-2: 0/0 new triple (561, 0:00:00.089553) +- INFO - ----- reclassify-concept-3: 4/4 new triples (565, 0:00:00.064027) +- INFO - ----- reclassify-concept-4: 4/4 new triples (569, 0:00:00.085822) +- DEBUG - ----- reclassify-concept-5: 0/0 new triple (569, 0:00:00.064385) +- DEBUG - ----- reify-roles-as-concept: 0/0 new triple (569, 0:00:00.163300) +- INFO - ----- reclassify-existing-variable: 13/13 new triples (582, 0:00:00.041098) +- DEBUG - ----- add-new-variable-for-reified-concept: 0/0 new triple (582, 0:00:00.074518) +- INFO - ----- add-amr-leaf-for-reclassified-concept: 9/9 new triples (591, 0:00:00.044130) +- DEBUG - ----- add-amr-leaf-for-reified-concept: 0/0 new triple (591, 0:00:00.049568) +- INFO - ----- add-amr-edge-for-core-relation: 6/6 new triples (597, 0:00:00.127213) +- DEBUG - ----- add-amr-edge-for-reified-concept: 0/0 new triple (597, 0:00:00.104635) +- INFO - ----- add-amr-edge-for-name-relation: 5/5 new triples (602, 0:00:00.097994) +- DEBUG - ----- add-value-for-quant-relation: 0/0 new triple (602, 0:00:00.101918) +- DEBUG - ----- add-amr-edge-for-polarity-relation: 0/0 new triple (602, 0:00:00.102668) +- INFO - ----- update-amr-edge-role-1: 3/3 new triples (605, 0:00:00.037165) +- INFO - ----- add-amr-root: 5/5 new triples (610, 0:00:00.034615) +- DEBUG - --- Serializing graph to tenet.tetras-libre.fr_demo_clara_01_preprocessing +- DEBUG - ----- step: preprocessing +- DEBUG - ----- id: https://tenet.tetras-libre.fr/demo/clara/01/ +- DEBUG - ----- work_file: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/technical-data/tenet.tetras-libre.fr_demo_clara_01-0/tenet.tetras-libre.fr_demo_clara_01_preprocessing.ttl +- DEBUG - ----- base: http://https://tenet.tetras-libre.fr/demo/clara/01//preprocessing +- INFO - ----- 54 triples extracted during preprocessing step +- INFO - -- Applying extraction step: transduction +- INFO - --- *** February Transduction *** Sequence: atomic extraction sequence +- INFO - ----- extract atom classes: 6/6 new triples (616, 0:00:00.049375) +- INFO - ----- extract atom individuals: 7/7 new triples (623, 0:00:00.058985) +- INFO - ----- extract atomic properties: 12/12 new triples (635, 0:00:00.056138) +- INFO - ----- extract atom values: 4/4 new triples (639, 0:00:00.044082) +- INFO - ----- extract atom phenomena: 7/7 new triples (646, 0:00:00.037112) +- INFO - ----- propagate atom relations: 4/12 new triples (650, 0:00:00.141900) +- INFO - --- *** February Transduction *** Sequence: phenomena analyze sequence (1) +- DEBUG - ----- analyze "polarity" phenomena: 0/0 new triple (650, 0:00:00.010470) +- DEBUG - ----- analyze modifier phenomena (mod): 0/0 new triple (650, 0:00:00.012524) +- INFO - --- *** February Transduction *** Sequence: phenomena analyze sequence (2) +- DEBUG - ----- analyze "or" phenomena (1): 0/0 new triple (650, 0:00:00.013205) +- DEBUG - ----- analyze "or" phenomena (2): 0/0 new triple (650, 0:00:00.013459) +- INFO - --- *** February Transduction *** Sequence: composite class extraction sequence +- DEBUG - ----- extract composite classes (1): 0/0 new triple (650, 0:00:00.021303) +- DEBUG - ----- extract composite classes (2): 0/0 new triple (650, 0:00:00.018889) +- DEBUG - --- Serializing graph to tenet.tetras-libre.fr_demo_clara_01_transduction +- DEBUG - ----- step: transduction +- DEBUG - ----- id: https://tenet.tetras-libre.fr/demo/clara/01/ +- DEBUG - ----- work_file: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/technical-data/tenet.tetras-libre.fr_demo_clara_01-0/tenet.tetras-libre.fr_demo_clara_01_transduction.ttl +- DEBUG - ----- base: http://https://tenet.tetras-libre.fr/demo/clara/01//transduction +- INFO - ----- 40 triples extracted during transduction step +- INFO - -- Applying extraction step: generation +- INFO - --- *** February Transduction *** Sequence: ODRL Rule Generation Sequence +- INFO - ----- generate ODRL rule: 1/1 new triple (651, 0:00:00.008208) +- DEBUG - --- Serializing graph to tenet.tetras-libre.fr_demo_clara_01_generation +- DEBUG - ----- step: generation +- DEBUG - ----- id: https://tenet.tetras-libre.fr/demo/clara/01/ +- DEBUG - ----- work_file: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/technical-data/tenet.tetras-libre.fr_demo_clara_01-0/tenet.tetras-libre.fr_demo_clara_01_generation.ttl +- DEBUG - ----- base: http://https://tenet.tetras-libre.fr/demo/clara/01//generation +- INFO - ----- 1 triples extracted during generation step +- DEBUG - --- Serializing graph to factoid file (/home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/technical-data/tenet.tetras-libre.fr_demo_clara_01-0/tenet.tetras-libre.fr_demo_clara_01_factoid.ttl) +- DEBUG - ----- Number of factoids: 1 +- DEBUG - ----- Graph base: http://https://tenet.tetras-libre.fr/demo/clara/01//factoid +- INFO - + === Final Ontology Generation === +- INFO - -- Making complete factoid graph by merging the result factoids +- INFO - ----- Total factoid number: 1 +- INFO - -- Serializing graph to factoid string +- INFO - ----- Graph base: http://https://tenet.tetras-libre.fr/demo/clara/01//factoid +- INFO - -- Serializing graph to factoid file +- INFO - ----- Ontology Turtle File: /home/lamenji/Workspace/Tetras/tenet/tests/output/aos01-20230411/aos01_factoid.ttl +- INFO - + === Done === +- INFO - + *** Execution Time *** +----- Function: create_ontology_from_amrld_file (tenet.main) +----- Total Time: 0:00:02.351338 +----- Process Time: 0:00:02.303288 + *** - *** +- DEBUG - handle_close[88d346bad84911ed9c6914abc581ea52]({'header': {'msg_id': 'e2e4aee1-6cb9e7de392b41ee961b7195_10499_244', 'msg_type': 'comm_close', 'username': 'lamenji', 'session': 'e2e4aee1-6cb9e7de392b41ee961b7195', 'date': datetime.datetime(2023, 4, 11, 15, 30, 50, 117111, tzinfo=tzutc()), 'version': '5.3'}, 'msg_id': 'e2e4aee1-6cb9e7de392b41ee961b7195_10499_244', 'msg_type': 'comm_close', 'parent_header': {}, 'metadata': {}, 'content': {'comm_id': '88d346bad84911ed9c6914abc581ea52', 'data': {}}, 'buffers': []}) diff --git a/tenet/transduction/net/__init__.py b/tenet/transduction/net/__init__.py index 235762f5acf708670cf6655bd1e1f31b6b67a829..fc989f72a52b422475ae61935310a9d4e6ab0783 100644 --- a/tenet/transduction/net/__init__.py +++ b/tenet/transduction/net/__init__.py @@ -19,3 +19,5 @@ from transduction.net.phenomena_net import PhenomenaNet from transduction.net.restriction_net import RestrictionNet from transduction.net.axiom_net import AxiomNet + +from transduction.net.rule_net import RuleNet diff --git a/tenet/transduction/net/rule_net.py b/tenet/transduction/net/rule_net.py new file mode 100644 index 0000000000000000000000000000000000000000..6d4e2d36ad729032701f7ba0ac1e4510b0a5fc6e --- /dev/null +++ b/tenet/transduction/net/rule_net.py @@ -0,0 +1,65 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Class Net +#------------------------------------------------------------------------------ +# Class to handle semantic nets +#============================================================================== + +from transduction.net import Net +from transduction.rdfterm_computer import produce_uriref, produce_literal + + +#============================================================================== +# Net Class +#============================================================================== + +class RuleNet(Net): + """ Class to handle semantic net. + """ + + #-------------------------------------------------------------------------- + # Constructor(s) + #-------------------------------------------------------------------------- + + def __init__(self, support_graph, uri=None): + + # -- Parent init + super().__init__(support_graph, uri) + + # -- Net Type + self.type_name = 'rule' + self.type_id = 'Rule_Net' + self.type_uri = f'net:{self.type_id}' + + # -- Net Attributes + self.attr_list += ['rule_name', 'rule_uri'] + self._rule_name = None + self._rule_uri = None + + + #-------------------------------------------------------------------------- + # Accessors for Net Attributes + #-------------------------------------------------------------------------- + + @property + def rule_name(self): + if self._rule_name is None: + self._rule_name = self.get_value_list_from_graph('rule_name') + return self._rule_name + + @rule_name.setter + def rule_name(self, new_value): + self._rule_name = self.set_attribute_value_list(new_value, produce_literal) + + + @property + def rule_uri(self): + if self._rule_uri is None: + self._rule_uri = self.get_value_list_from_graph('rule_uri') + return self._rule_uri + + @rule_uri.setter + def rule_uri(self, new_value): + self._rule_uri = self.set_attribute_value_list(new_value, produce_uriref) diff --git a/tests/input/amrDocuments/dev/asail_odrl_sentences/s01.stog.amr.ttl b/tests/input/amrDocuments/dev/asail_odrl_sentences/s01.stog.amr.ttl new file mode 100644 index 0000000000000000000000000000000000000000..e28383d75e9c7176960ad64a940083add686106d --- /dev/null +++ b/tests/input/amrDocuments/dev/asail_odrl_sentences/s01.stog.amr.ttl @@ -0,0 +1,44 @@ +@prefix ns1: <http://amr.isi.edu/rdf/core-amr#> . +@prefix ns2: <http://amr.isi.edu/frames/ld/v1.2.2/> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +ns1:Concept a rdfs:Class ; + rdfs:label "AMR-Concept" . + +ns1:Role a rdfs:Class ; + rdfs:label "AMR-Role" . + +<http://amr.isi.edu/amr_data/document-01#root01> a ns1:AMR ; + ns1:has-id "document-01" ; + ns1:has-sentence "Movie9898 can be used." ; + ns1:root <http://amr.isi.edu/amr_data/document-01#p> . + +ns2:possible-01.ARG1 a ns2:FrameRole . + +ns2:use-01.ARG1 a ns2:FrameRole . + +ns1:NamedEntity a ns1:Concept ; + rdfs:label "AMR-EntityType", + "AMR-Term" . + +<http://amr.isi.edu/amr_data/document-01#m> a <http://amr.isi.edu/rdf/amr-terms#movie> ; + rdfs:label "9898" . + +<http://amr.isi.edu/amr_data/document-01#p> a ns2:possible-01 ; + ns2:possible-01.ARG1 <http://amr.isi.edu/amr_data/document-01#u> . + +<http://amr.isi.edu/amr_data/document-01#u> a ns2:use-01 ; + ns2:use-01.ARG1 <http://amr.isi.edu/amr_data/document-01#m> . + +ns2:possible-01 a ns1:Frame . + +ns2:use-01 a ns1:Frame . + +<http://amr.isi.edu/rdf/amr-terms#movie> a ns1:Concept . + +ns2:FrameRole a ns1:Role ; + rdfs:label "AMR-PropBank-Role" . + +ns1:Frame a ns1:Concept ; + rdfs:label "AMR-PropBank-Frame" . + diff --git a/tests/input/amrDocuments/dev/asail_odrl_sentences/s02.stog.amr.ttl b/tests/input/amrDocuments/dev/asail_odrl_sentences/s02.stog.amr.ttl new file mode 100644 index 0000000000000000000000000000000000000000..9975e6ad73711d7108e51da0d338145709fb232a --- /dev/null +++ b/tests/input/amrDocuments/dev/asail_odrl_sentences/s02.stog.amr.ttl @@ -0,0 +1,51 @@ +@prefix ns1: <http://amr.isi.edu/frames/ld/v1.2.2/> . +@prefix ns2: <http://amr.isi.edu/rdf/core-amr#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +ns2:Concept a rdfs:Class ; + rdfs:label "AMR-Concept" . + +ns2:Role a rdfs:Class ; + rdfs:label "AMR-Role" . + +<http://amr.isi.edu/amr_data/document-02#root01> a ns2:AMR ; + ns2:has-id "document-02" ; + ns2:has-sentence "John must play the movie." ; + ns2:root <http://amr.isi.edu/amr_data/document-02#o> . + +ns1:obligate-01.ARG2 a ns1:FrameRole . + +ns1:play-02.ARG0 a ns1:FrameRole . + +ns1:play-02.ARG1 a ns1:FrameRole . + +<http://amr.isi.edu/amr_data/document-02#m> a <http://amr.isi.edu/rdf/amr-terms#movie> . + +<http://amr.isi.edu/amr_data/document-02#o> a ns1:obligate-01 ; + ns1:obligate-01.ARG2 <http://amr.isi.edu/amr_data/document-02#p> . + +<http://amr.isi.edu/amr_data/document-02#p> a ns1:play-02 ; + ns1:play-02.ARG0 <http://amr.isi.edu/amr_data/document-02#p2> ; + ns1:play-02.ARG1 <http://amr.isi.edu/amr_data/document-02#m> . + +<http://amr.isi.edu/amr_data/document-02#p2> a <http://amr.isi.edu/entity-types#person> ; + rdfs:label "John" . + +<http://amr.isi.edu/entity-types#person> a ns2:NamedEntity . + +ns1:obligate-01 a ns2:Frame . + +ns1:play-02 a ns2:Frame . + +<http://amr.isi.edu/rdf/amr-terms#movie> a ns2:Concept . + +ns2:NamedEntity a ns2:Concept ; + rdfs:label "AMR-EntityType", + "AMR-Term" . + +ns2:Frame a ns2:Concept ; + rdfs:label "AMR-PropBank-Frame" . + +ns1:FrameRole a ns2:Role ; + rdfs:label "AMR-PropBank-Role" . + diff --git a/tests/input/amrDocuments/dev/asail_odrl_sentences/s03.stog.amr.ttl b/tests/input/amrDocuments/dev/asail_odrl_sentences/s03.stog.amr.ttl new file mode 100644 index 0000000000000000000000000000000000000000..f487d2183f484611479fe3759a7bf0b8f9830e6c --- /dev/null +++ b/tests/input/amrDocuments/dev/asail_odrl_sentences/s03.stog.amr.ttl @@ -0,0 +1,53 @@ +@prefix ns1: <http://amr.isi.edu/rdf/core-amr#> . +@prefix ns2: <http://amr.isi.edu/rdf/amr-terms#> . +@prefix ns3: <http://amr.isi.edu/frames/ld/v1.2.2/> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +ns1:Concept a rdfs:Class ; + rdfs:label "AMR-Concept" . + +ns1:Role a rdfs:Class ; + rdfs:label "AMR-Role" . + +<http://amr.isi.edu/amr_data/document-03#root01> a ns1:AMR ; + ns1:has-id "document-03" ; + ns1:has-sentence "John is not allowed to play the movie.." ; + ns1:root <http://amr.isi.edu/amr_data/document-03#a> . + +ns3:allow-01.ARG1 a ns3:FrameRole . + +ns3:play-01.ARG0 a ns3:FrameRole . + +ns3:play-01.ARG1 a ns3:FrameRole . + +<http://amr.isi.edu/amr_data/document-03#a> a ns3:allow-01 ; + ns3:allow-01.ARG1 <http://amr.isi.edu/amr_data/document-03#p> ; + ns2:polarity "-" . + +<http://amr.isi.edu/amr_data/document-03#m> a ns2:movie . + +<http://amr.isi.edu/amr_data/document-03#p> a ns3:play-01 ; + ns3:play-01.ARG0 <http://amr.isi.edu/amr_data/document-03#p2> ; + ns3:play-01.ARG1 <http://amr.isi.edu/amr_data/document-03#m> . + +<http://amr.isi.edu/amr_data/document-03#p2> a <http://amr.isi.edu/entity-types#person> ; + rdfs:label "John" . + +<http://amr.isi.edu/entity-types#person> a ns1:NamedEntity . + +ns3:allow-01 a ns1:Frame . + +ns3:play-01 a ns1:Frame . + +ns2:movie a ns1:Concept . + +ns1:NamedEntity a ns1:Concept ; + rdfs:label "AMR-EntityType", + "AMR-Term" . + +ns1:Frame a ns1:Concept ; + rdfs:label "AMR-PropBank-Frame" . + +ns3:FrameRole a ns1:Role ; + rdfs:label "AMR-PropBank-Role" . + diff --git a/tests/input/amrDocuments/dev/asail_odrl_sentences/s04.stog.amr.ttl b/tests/input/amrDocuments/dev/asail_odrl_sentences/s04.stog.amr.ttl new file mode 100644 index 0000000000000000000000000000000000000000..88079a4d82b32fde72a4e7fd7592a86a045d2a82 --- /dev/null +++ b/tests/input/amrDocuments/dev/asail_odrl_sentences/s04.stog.amr.ttl @@ -0,0 +1,60 @@ +@prefix ns1: <http://amr.isi.edu/rdf/core-amr#> . +@prefix ns2: <http://amr.isi.edu/rdf/amr-terms#> . +@prefix ns3: <http://amr.isi.edu/frames/ld/v1.2.2/> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +ns1:Concept a rdfs:Class ; + rdfs:label "AMR-Concept" . + +ns1:Role a rdfs:Class ; + rdfs:label "AMR-Role" . + +<http://amr.isi.edu/amr_data/document-01#root01> a ns1:AMR ; + ns1:has-id "document-01" ; + ns1:has-sentence "Movie9899 can be displayed only in Germany." ; + ns1:root <http://amr.isi.edu/amr_data/document-01#p> . + +ns3:display-01.ARG1 a ns3:FrameRole . + +ns3:display-01.ARG2 a ns3:FrameRole . + +ns3:possible-01.ARG1 a ns3:FrameRole . + +ns2:mod a ns1:Role . + +<http://amr.isi.edu/amr_data/document-01#c> a <http://amr.isi.edu/entity-types#country> ; + rdfs:label "Germany" ; + ns2:mod <http://amr.isi.edu/amr_data/document-01#o> . + +<http://amr.isi.edu/amr_data/document-01#d> a ns3:display-01 ; + ns3:display-01.ARG1 <http://amr.isi.edu/amr_data/document-01#m> ; + ns3:display-01.ARG2 <http://amr.isi.edu/amr_data/document-01#c> . + +<http://amr.isi.edu/amr_data/document-01#m> a ns2:movie ; + rdfs:label "9899" . + +<http://amr.isi.edu/amr_data/document-01#o> a ns2:only . + +<http://amr.isi.edu/amr_data/document-01#p> a ns3:possible-01 ; + ns3:possible-01.ARG1 <http://amr.isi.edu/amr_data/document-01#d> . + +<http://amr.isi.edu/entity-types#country> a ns1:NamedEntity . + +ns3:display-01 a ns1:Frame . + +ns3:possible-01 a ns1:Frame . + +ns2:movie a ns1:Concept . + +ns2:only a ns1:Concept . + +ns1:NamedEntity a ns1:Concept ; + rdfs:label "AMR-EntityType", + "AMR-Term" . + +ns1:Frame a ns1:Concept ; + rdfs:label "AMR-PropBank-Frame" . + +ns3:FrameRole a ns1:Role ; + rdfs:label "AMR-PropBank-Role" . + diff --git a/tests/input/amrDocuments/dev/asail_odrl_sentences/s05.stog.amr.ttl b/tests/input/amrDocuments/dev/asail_odrl_sentences/s05.stog.amr.ttl new file mode 100644 index 0000000000000000000000000000000000000000..9baeeb62c3e3be0c145fd172d685084ccec8ed2b --- /dev/null +++ b/tests/input/amrDocuments/dev/asail_odrl_sentences/s05.stog.amr.ttl @@ -0,0 +1,67 @@ +@prefix ns1: <http://amr.isi.edu/frames/ld/v1.2.2/> . +@prefix ns2: <http://amr.isi.edu/rdf/amr-terms#> . +@prefix ns3: <http://amr.isi.edu/rdf/core-amr#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +ns3:Concept a rdfs:Class ; + rdfs:label "AMR-Concept" . + +ns3:Role a rdfs:Class ; + rdfs:label "AMR-Role" . + +<http://amr.isi.edu/amr_data/document-02#root01> a ns3:AMR ; + ns3:has-id "document-02" ; + ns3:has-sentence "Movie9899 can be displayed only after 2019.." ; + ns3:root <http://amr.isi.edu/amr_data/document-02#p> . + +ns1:display-01.ARG1 a ns1:FrameRole . + +ns1:possible-01.ARG1 a ns1:FrameRole . + +ns2:mod a ns3:Role . + +ns2:op1 a ns3:Role . + +ns2:time a ns3:Role . + +ns3:NamedEntity a ns3:Concept ; + rdfs:label "AMR-EntityType", + "AMR-Term" . + +<http://amr.isi.edu/amr_data/document-02#a> a ns3:after ; + ns2:mod <http://amr.isi.edu/amr_data/document-02#o> ; + ns2:op1 <http://amr.isi.edu/amr_data/document-02#d2> . + +<http://amr.isi.edu/amr_data/document-02#d> a ns1:display-01 ; + ns1:display-01.ARG1 <http://amr.isi.edu/amr_data/document-02#m> ; + ns2:time <http://amr.isi.edu/amr_data/document-02#a> . + +<http://amr.isi.edu/amr_data/document-02#d2> a ns3:date-entity ; + ns2:year "2019" . + +<http://amr.isi.edu/amr_data/document-02#m> a ns2:movie ; + rdfs:label "9899" . + +<http://amr.isi.edu/amr_data/document-02#o> a ns2:only . + +<http://amr.isi.edu/amr_data/document-02#p> a ns1:possible-01 ; + ns1:possible-01.ARG1 <http://amr.isi.edu/amr_data/document-02#d> . + +ns1:display-01 a ns3:Frame . + +ns1:possible-01 a ns3:Frame . + +ns2:movie a ns3:Concept . + +ns2:only a ns3:Concept . + +ns3:after a ns3:Concept . + +ns3:date-entity a ns3:Concept . + +ns1:FrameRole a ns3:Role ; + rdfs:label "AMR-PropBank-Role" . + +ns3:Frame a ns3:Concept ; + rdfs:label "AMR-PropBank-Frame" . + diff --git a/tests/test_tenet_clara_main.py b/tests/test_tenet_clara_main.py new file mode 100644 index 0000000000000000000000000000000000000000..d626c9a0aa5c7a5777fbc7e11fd83360af0cb990 --- /dev/null +++ b/tests/test_tenet_clara_main.py @@ -0,0 +1,99 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Development Extraction Running Script +#------------------------------------------------------------------------------ +# Script to run the extraction process (development) +#============================================================================== + +import subprocess, os +from datetime import datetime + +FILE_PATH = f'{os.path.dirname(os.path.abspath(__file__))}' +INPUT_DIR_PATH = f'{FILE_PATH}/input/' +OUTPUT_DIR_PATH = f'{FILE_PATH}/output/' + +from context import tenet + + + +#============================================================================== +# AMR Extraction +#============================================================================== + +# ----------------------------------------------- +# Input / Output Data +# ----------------------------------------------- + +# -- Input Data +test_data_dir = f'{INPUT_DIR_PATH}amrDocuments/' + +uuid_num = '01' +amrld_dir_path = f'{test_data_dir}dev/asail_odrl_sentences/' +amrld_file_path = f'{amrld_dir_path}s{uuid_num}.stog.amr.ttl' +base_output_name = f'aos{uuid_num}' +onto_prefix = f"https://tenet.tetras-libre.fr/demo/clara/{uuid_num}/" + + +# -- Output references +time_ref = f'{datetime.now().strftime("%Y%m%d")}' +out_dir_path = f'{OUTPUT_DIR_PATH}{base_output_name}-{time_ref}/' +os.makedirs(out_dir_path, exist_ok=True) +out_file_name = f'{base_output_name}_factoid.ttl' +out_file_path = f'{out_dir_path}{out_file_name}' +technical_dir_path = f'{out_dir_path}technical-data/' +#technical_dir_path = None + +# ----------------------------------------------- +# Extraction using tenet main methods +# ----------------------------------------------- + +os.chdir('..') +# -- Extraction from a file +factoids = tenet.create_ontology_from_amrld_file(amrld_file_path, + onto_prefix=onto_prefix, + out_file_path=out_file_path, + technical_dir_path=technical_dir_path) + + +# -- Extraction from a directory (all files in a directory) +# factoids = tenet.create_ontology_from_amrld_dir(amrld_dir_path, +# onto_prefix=onto_prefix, +# out_file_path=out_file_path, +# technical_dir_path=technical_dir_path) + +# print(factoids) + + +# ----------------------------------------------- +# Extraction using extract command as subprocess +# ----------------------------------------------- + +# extract_command = f'{os.path.dirname(os.path.abspath(__file__))}/../tenet/extract.py' +# tenet_process = ["python3", extract_command, +# "--source_type", 'amr', +# "--source_corpus", amrld_dir_path, +# "--onto_prefix", onto_prefix, +# "--out_file_path", out_file_path] +# if technical_dir_path is not None: +# tenet_process += ["--technical_dir_path", technical_dir_path] +# subprocess.run(tenet_process) + + +#============================================================================== +# UNL Extraction +#============================================================================== + +# -- Target: default-ontology +# base_ontology_path = f'{INPUT_DIR_PATH}targetFrameStructure/default-ontology.ttl' +# ontology_seed_path = f'{INPUT_DIR_PATH}targetFrameStructure/default-ontology-seed.ttl' +# #target_ontology_namespace = "https://tenet.tetras-libre.fr/default-ontology/" + +# unlrdf_file_path = f'{INPUT_DIR_PATH}/unlDocuments/' + req_100 + +# tenet.main.create_ontology_from_unlrdf_file(unlrdf_file_path, +# base_ontology_path=base_ontology_path, +# ontology_seed_path=ontology_seed_path, +# #onto_prefix=target_ontology_namespace, +# out_file_path=OUTPUT_DIR_PATH) \ No newline at end of file