Skip to content
Snippets Groups Projects
Commit 56a8ccca authored by Aurélien Lamercerie's avatar Aurélien Lamercerie
Browse files

New AMR Rule: transduction.phenomena_and_analyzer_1 (and 2)

parent def0589f
Branches
Tags
No related merge requests found
......@@ -19,6 +19,8 @@ from scheme.amr_clara_rule.transduction.phenomena_polarity_analyzer_5 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.transduction.phenomena_and_analyzer_1 import *
from scheme.amr_clara_rule.transduction.phenomena_and_analyzer_2 import *
from scheme.amr_clara_rule.transduction.odrl_action_extractor import *
from scheme.amr_clara_rule.transduction.odrl_rule_extractor import *
......
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: Rule to conjunctive phenomena and (rule 1)
#------------------------------------------------------------------------------
# Net Expansion AMR rule to analyse conjunctive phenomena (and)
# Rule: property(class, and_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, and_phenomena)
#==============================================================================
CONJUNCTION_PHENOMENA_URI = 'amr:phenomena_conjunction_and'
def __search_pattern(graph):
select_data_list = ['?property_net', '?class_net', '?phenomena_net']
clause_list = [f'?property_net a [rdfs:subClassOf* net:Property_Net].',
f'?class_net a [rdfs:subClassOf* net:Class_Net].',
f'?phenomena_net a [rdfs:subClassOf* net:Phenomena_Net].',
f'?phenomena_net net:hasPhenomenaType {CONJUNCTION_PHENOMENA_URI}.',
f'?property_net amr:role_ARG0 ?class_net.',
f'?property_net amr:role_ARG1 ?phenomena_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 __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
#==============================================================================
def analyze_phenomena_and_1(graph):
# -- Rule Initialization
rule_label = 'analyze "and" phenomena (1)'
rule_triple_list = []
# -- Search for patterns
_, pattern_set = __search_pattern(graph)
# -- Pattern Analysis
for pattern in pattern_set:
class_net_1 = net.ClassNet(graph, uri=pattern.class_net)
property_net = net.PropertyNet(graph, uri=pattern.property_net)
phenomena_net = net.PhenomenaNet(graph, uri=pattern.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
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: Rule to conjunctive phenomena and (rule 2)
#------------------------------------------------------------------------------
# Net Expansion AMR rule to analyse conjunctive phenomena (and)
# Rule: property(property, and_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, and_phenomena)
#==============================================================================
CONJUNCTION_PHENOMENA_URI = 'amr:phenomena_conjunction_and'
def __search_pattern(graph):
select_data_list = ['?property_net_core', '?property_net_arg0', '?phenomena_net']
clause_list = [f'?property_net_core a [rdfs:subClassOf* net:Property_Net].',
f'?property_net_arg0 a [rdfs:subClassOf* net:Property_Net].',
f'?phenomena_net a [rdfs:subClassOf* net:Phenomena_Net].',
f'?phenomena_net net:hasPhenomenaType {CONJUNCTION_PHENOMENA_URI}.',
f'?property_net_core amr:role_ARG0 ?property_net_arg0.',
f'?property_net_core amr:role_ARG1 ?phenomena_net.']
query_code = generate_select_query(graph, select_data_list, clause_list)
result_set = graph.query(query_code)
return query_code, result_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_and_2
#==============================================================================
def analyze_phenomena_and_2(graph):
# -- Rule Initialization
rule_label = 'analyze "and" phenomena (2)'
rule_triple_list = []
# -- Search for patterns
_, pattern_set = __search_pattern(graph)
# -- Pattern Analysis
for pattern in pattern_set:
property_net_1 = net.PropertyNet(graph, uri=pattern.property_net_arg0)
property_net_2 = net.PropertyNet(graph, uri=pattern.property_net_core)
phenomena_net = net.PhenomenaNet(graph, uri=pattern.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
......@@ -192,7 +192,9 @@ phenomena_analyze_sequence_1 = ['phenomena analyze sequence (1)',
phenomena_analyze_sequence_2 = ['phenomena analyze sequence (2)',
rule.analyze_phenomena_or_1,
rule.analyze_phenomena_or_2]
rule.analyze_phenomena_or_2,
rule.analyze_phenomena_and_1,
rule.analyze_phenomena_and_2]
composite_class_extraction_sequence = ['composite class extraction sequence',
rule.extract_composite_class_1,
......
This diff is collapsed.
......@@ -546,30 +546,6 @@ net:atomType a owl:AnnotationProperty ;
rdfs:label "atom type" ;
rdfs:subPropertyOf net:objectType .
net:axiom_disjointProperty_not-share_share_s a net:Axiom_Net ;
net:composeFrom net:atomProperty_share_s,
net:compositeProperty_not-share_s ;
net:coverBaseNode :leaf_share-01_s ;
net:coverNode :leaf_share-01_s ;
net:hasAxiomName "disjointProperty" ;
net:hasAxiomURI owl:propertyDisjointWith ;
net:hasNaming "disjointProperty_not-share_share" ;
net:hasNetArgument net:atomProperty_share_s,
net:compositeProperty_not-share_s ;
net:hasStructure "cc-sentence-examples-03" .
net:axiom_disjointProperty_share_not-share_s a net:Axiom_Net ;
net:composeFrom net:atomProperty_share_s,
net:compositeProperty_not-share_s ;
net:coverBaseNode :leaf_share-01_s ;
net:coverNode :leaf_share-01_s ;
net:hasAxiomName "disjointProperty" ;
net:hasAxiomURI owl:propertyDisjointWith ;
net:hasNaming "disjointProperty_share_not-share" ;
net:hasNetArgument net:atomProperty_share_s,
net:compositeProperty_not-share_s ;
net:hasStructure "cc-sentence-examples-03" .
net:class a owl:Class ;
rdfs:label "class" ;
rdfs:subClassOf net:Type .
......@@ -919,6 +895,15 @@ sys:Feature a owl:Class ;
sys:Out_AnnotationProperty a owl:AnnotationProperty .
net:Axiom_Net a owl:Class ;
rdfs:subClassOf net:Net .
net:Composite_Property_Net a owl:Class ;
rdfs:subClassOf net:Property_Net .
net:Deprecated_Net a owl:Class ;
rdfs:subClassOf net:Net .
net:Feature a owl:Class ;
rdfs:subClassOf net:Net_Structure .
......@@ -968,8 +953,7 @@ net:phenomena_conjunction-AND_a a net:Phenomena_Net ;
net:phenomena_conjunction_c a net:Phenomena_Net ;
:role_ARG1 net:atomProperty_license_l2 ;
:role_ARG2 net:atomProperty_share_s,
net:compositeProperty_not-share_s ;
:role_ARG2 net:atomProperty_share_s ;
net:coverBaseNode :leaf_contrast-01_c ;
net:coverNode :leaf_contrast-01_c ;
net:hasNaming "conjunction" ;
......@@ -1012,6 +996,13 @@ net:restriction_shareing_material a net:Restriction_Net ;
net:hasRestrictionNetValue net:atomClass_material_m ;
net:hasRestrictionOnProperty net:atomProperty_share_s .
net:value_negative_blankNode a net:Value_Net ;
net:hasNaming "negative" ;
net:hasStructure "cc-sentence-examples-03" ;
net:hasValueLabel "negative" ;
net:trackProgress net:initialized,
net:relation_propagated .
<http://amr.isi.edu/amr_data/cc-sentence-examples-03#a> a ns3:and ;
ns2:op1 <http://amr.isi.edu/amr_data/cc-sentence-examples-03#p2> ;
ns2:op2 <http://amr.isi.edu/amr_data/cc-sentence-examples-03#r> ;
......@@ -1116,12 +1107,6 @@ sys:Out_ObjectProperty a owl:ObjectProperty .
net:Class_Net a owl:Class ;
rdfs:subClassOf net:Net .
net:Composite_Property_Net a owl:Class ;
rdfs:subClassOf net:Property_Net .
net:Deprecated_Net a owl:Class ;
rdfs:subClassOf net:Net .
net:Phenomena_Net a owl:Class ;
rdfs:subClassOf net:Net .
......@@ -1156,16 +1141,36 @@ net:atomProperty_license_l2 a net:Atom_Property_Net ;
net:trackProgress net:initialized,
net:relation_propagated .
net:objectProperty a owl:AnnotationProperty ;
rdfs:label "object attribute" .
net:value_negative_blankNode a net:Value_Net ;
net:hasNaming "negative" ;
net:atomProperty_share_s a net:Atom_Property_Net ;
:role_ARG0 net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y,
net:individual_you-produceing-material_fromClass,
net:individual_you-reproduceing-material_fromClass,
net:individual_you-shareing-material_fromClass,
net:individual_you_fromClass ;
:role_ARG1 net:atomClass_material_m ;
:role_polarity net:value_negative_blankNode ;
net:coverBaseNode :leaf_share-01_s ;
net:coverNode :leaf_share-01_s ;
net:hasNaming "share" ;
net:hasPropertyName "share" ;
net:hasPropertyName01 "shareing" ;
net:hasPropertyName10 "share-by" ;
net:hasPropertyName12 "share-of" ;
net:hasPropertyType owl:ObjectProperty ;
net:hasStructure "cc-sentence-examples-03" ;
net:hasValueLabel "negative" ;
net:isCoreRoleLinked true ;
net:targetArgumentNode :leaf_material_m,
:leaf_you_y,
:value_negative ;
net:trackProgress net:initialized,
net:relation_propagated .
net:objectProperty a owl:AnnotationProperty ;
rdfs:label "object attribute" .
<http://amr.isi.edu/amr_data/cc-sentence-examples-03#l> a ns11:license-01 ;
ns2:mod <http://amr.isi.edu/amr_data/cc-sentence-examples-03#t> ;
rdfs:subClassOf :AMR_Linked_Data .
......@@ -1216,9 +1221,6 @@ ns11:license-01 a ns3:Frame ;
net:Atom_Class_Net a owl:Class ;
rdfs:subClassOf net:Class_Net .
net:Axiom_Net a owl:Class ;
rdfs:subClassOf net:Net .
net:Composite_Class_Net a owl:Class ;
rdfs:subClassOf net:Class_Net .
......@@ -1304,22 +1306,52 @@ sys:Out_Structure a owl:Class ;
net:Individual_Net a owl:Class ;
rdfs:subClassOf net:Net .
net:compositeProperty_not-share_s a net:Composite_Property_Net ;
:role_ARG0 net:atomClass_you_y,
net:individual_you-produceing-material_fromClass a net:Individual_Net ;
net:coverBaseNode :leaf_you_y ;
net:coverNode :leaf_you_y ;
net:fromClassNet net:compositeClass_you-produceing-material_y ;
net:hasBaseClassName "Feature" ;
net:hasIndividualLabel "you-produceing-material" ;
net:hasMotherClassNet net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y,
net:individual_you-produceing-material_fromClass,
net:individual_you-reproduceing-material_fromClass,
net:individual_you-shareing-material_fromClass,
net:individual_you_fromClass ;
:role_ARG1 net:atomClass_material_m ;
:role_polarity net:value_negative_blankNode ;
net:composeFrom net:atomProperty_share_s ;
net:coverBaseNode :leaf_share-01_s ;
net:coverNode :leaf_share-01_s ;
net:hasNaming "not-share" ;
net:hasPropertyType owl:ObjectProperty ;
net:compositeClass_you-shareing-material_y ;
net:hasStructure "cc-sentence-examples-03" .
net:individual_you-reproduceing-material_fromClass a net:Individual_Net ;
net:coverBaseNode :leaf_you_y ;
net:coverNode :leaf_you_y ;
net:fromClassNet net:compositeClass_you-reproduceing-material_y ;
net:hasBaseClassName "Feature" ;
net:hasIndividualLabel "you-reproduceing-material" ;
net:hasMotherClassNet net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y ;
net:hasStructure "cc-sentence-examples-03" .
net:individual_you-shareing-material_fromClass a net:Individual_Net ;
net:coverBaseNode :leaf_you_y ;
net:coverNode :leaf_you_y ;
net:fromClassNet net:compositeClass_you-shareing-material_y ;
net:hasBaseClassName "Feature" ;
net:hasIndividualLabel "you-shareing-material" ;
net:hasMotherClassNet net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y ;
net:hasStructure "cc-sentence-examples-03" .
net:individual_you_fromClass a net:Individual_Net ;
net:coverBaseNode :leaf_you_y ;
net:coverNode :leaf_you_y ;
net:fromClassNet net:atomClass_you_y ;
net:hasBaseClassName "Feature" ;
net:hasIndividualLabel "you" ;
net:hasMotherClassNet net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y ;
net:hasStructure "cc-sentence-examples-03" .
net:netProperty a owl:AnnotationProperty ;
......@@ -1351,6 +1383,13 @@ net:netProperty a owl:AnnotationProperty ;
:hasConcept :concept_reproduce-01 ;
:hasVariable :variable_r .
:leaf_share-01_s a :AMR_Leaf ;
:edge_s_ARG0_y :leaf_you_y ;
:edge_s_ARG1_m :leaf_material_m ;
:edge_s_polarity_negative :value_negative ;
:hasConcept :concept_share-01 ;
:hasVariable :variable_s .
:leaf_this_t a :AMR_Leaf ;
:hasConcept :concept_this ;
:hasVariable :variable_t .
......@@ -1415,54 +1454,6 @@ net:atomProperty_reproduce_r a net:Atom_Property_Net ;
net:trackProgress net:initialized,
net:relation_propagated .
net:individual_you-produceing-material_fromClass a net:Individual_Net ;
net:coverBaseNode :leaf_you_y ;
net:coverNode :leaf_you_y ;
net:fromClassNet net:compositeClass_you-produceing-material_y ;
net:hasBaseClassName "Feature" ;
net:hasIndividualLabel "you-produceing-material" ;
net:hasMotherClassNet net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y ;
net:hasStructure "cc-sentence-examples-03" .
net:individual_you-reproduceing-material_fromClass a net:Individual_Net ;
net:coverBaseNode :leaf_you_y ;
net:coverNode :leaf_you_y ;
net:fromClassNet net:compositeClass_you-reproduceing-material_y ;
net:hasBaseClassName "Feature" ;
net:hasIndividualLabel "you-reproduceing-material" ;
net:hasMotherClassNet net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y ;
net:hasStructure "cc-sentence-examples-03" .
net:individual_you-shareing-material_fromClass a net:Individual_Net ;
net:coverBaseNode :leaf_you_y ;
net:coverNode :leaf_you_y ;
net:fromClassNet net:compositeClass_you-shareing-material_y ;
net:hasBaseClassName "Feature" ;
net:hasIndividualLabel "you-shareing-material" ;
net:hasMotherClassNet net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y ;
net:hasStructure "cc-sentence-examples-03" .
net:individual_you_fromClass a net:Individual_Net ;
net:coverBaseNode :leaf_you_y ;
net:coverNode :leaf_you_y ;
net:fromClassNet net:atomClass_you_y ;
net:hasBaseClassName "Feature" ;
net:hasIndividualLabel "you" ;
net:hasMotherClassNet net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y ;
net:hasStructure "cc-sentence-examples-03" .
rdf:Property a owl:Class .
:AMR_Predicat_Concept a owl:Class ;
......@@ -1474,31 +1465,14 @@ rdf:Property a owl:Class .
net:Relation a owl:Class ;
rdfs:subClassOf net:Net_Structure .
net:atomProperty_share_s a net:Atom_Property_Net,
net:Deprecated_Net ;
:role_ARG0 net:atomClass_you_y,
net:compositeClass_you-produceing-material_y,
net:compositeClass_you-reproduceing-material_y,
net:compositeClass_you-shareing-material_y,
net:individual_you-produceing-material_fromClass,
net:individual_you-reproduceing-material_fromClass,
net:individual_you-shareing-material_fromClass,
net:individual_you_fromClass ;
:role_ARG1 net:atomClass_material_m ;
:role_polarity net:value_negative_blankNode ;
net:coverBaseNode :leaf_share-01_s ;
net:coverNode :leaf_share-01_s ;
net:hasNaming "share" ;
net:hasPropertyName "share" ;
net:hasPropertyName01 "shareing" ;
net:hasPropertyName10 "share-by" ;
net:hasPropertyName12 "share-of" ;
net:hasPropertyType owl:ObjectProperty ;
net:atomClass_material_m a net:Atom_Class_Net ;
net:coverBaseNode :leaf_material_m ;
net:coverNode :leaf_material_m ;
net:coverNodeCount 1 ;
net:hasClassName "material" ;
net:hasClassType sys:Entity ;
net:hasNaming "material" ;
net:hasStructure "cc-sentence-examples-03" ;
net:isCoreRoleLinked true ;
net:targetArgumentNode :leaf_material_m,
:leaf_you_y,
:value_negative ;
net:trackProgress net:initialized,
net:relation_propagated .
......@@ -1525,17 +1499,6 @@ net:Type a owl:Class ;
rdfs:label "Semantic Net Type" ;
rdfs:subClassOf net:Net_Structure .
net:atomClass_material_m a net:Atom_Class_Net ;
net:coverBaseNode :leaf_material_m ;
net:coverNode :leaf_material_m ;
net:coverNodeCount 1 ;
net:hasClassName "material" ;
net:hasClassType sys:Entity ;
net:hasNaming "material" ;
net:hasStructure "cc-sentence-examples-03" ;
net:trackProgress net:initialized,
net:relation_propagated .
net:has_object a owl:AnnotationProperty ;
rdfs:label "relation" ;
rdfs:subPropertyOf net:netProperty .
......@@ -1593,13 +1556,6 @@ net:compositeClass_you-shareing-material_y a net:Composite_Class_Net ;
net:trackProgress net:initialized,
net:relation_propagated .
:leaf_share-01_s a :AMR_Leaf ;
:edge_s_ARG0_y :leaf_you_y ;
:edge_s_ARG1_m :leaf_material_m ;
:edge_s_polarity_negative :value_negative ;
:hasConcept :concept_share-01 ;
:hasVariable :variable_s .
:AMR_Variable a owl:Class ;
rdfs:subClassOf :AMR_Element .
......
This diff is collapsed.
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: Extraction Rule Test
#------------------------------------------------------------------------------
# Script to test rules under development
#==============================================================================
import subprocess, os
from rdflib import Graph, Namespace
from rdflib.namespace import NamespaceManager, FOAF, RDF
from rdflib import URIRef, Literal, BNode
FILE_PATH = f'{os.path.dirname(os.path.abspath(__file__))}'
INPUT_DIR_PATH = f'{FILE_PATH}/test_data/'
OUTPUT_DIR_PATH = f'{FILE_PATH}/test_data/'
TEST_FILE_NAME_1 = 'negation-devGraph-1'
TEST_FILE_NAME_2 = 'negation-devGraph-2'
from context import tenet
from tenet.scheme.amr_clara_rule.transduction import phenomena_and_analyzer_1 as rule_1
from tenet.scheme.amr_clara_rule.transduction import phenomena_and_analyzer_2 as rule_2
from tenet.scheme import amr_clara_rule as rule
from tenet.transduction.rdfterm_computer import __update_uri_with_prefix
from tenet.transduction import query_builder
from tenet.transduction import prefix_handle
INDENT_STR = ' '
#==============================================================================
# Useful Methods
#==============================================================================
def load_test_graph(test_file_name):
print(f'\n -- Test Graph Loading')
graph = Graph()
prefix_handle.update_graph_namespacemanager(graph)
graph_path = f'{INPUT_DIR_PATH}{test_file_name}.ttl'
graph.parse(graph_path)
print(f" ----- Graph Loaded ({len(graph)})")
return graph
def print_triple(graph, triple, num=-1):
num_str = f'[{num}]' if num > -1 else '[-]'
(s, p, o) = triple
s = __update_uri_with_prefix(graph, s)
p = __update_uri_with_prefix(graph, p)
o = __update_uri_with_prefix(graph, o)
print(f' {num_str} {s} {p} {o}')
def add_triples_in_graph(test_file_name, graph, triple_list):
print(f'\n -- Adding triple(s) in graph')
print(f" ----- Graph length before update: {len(graph)}")
print(f" ----- Number of triples to add: {len(triple_list)}")
print(f" ----- Added triples:")
n = 0
graph_length = len(graph)
for triple in triple_list:
graph.add(triple)
if graph_length < len(graph):
n += 1
graph_length = len(graph)
print_triple(graph, triple, num=n)
print(f" ----- Graph length after update: {len(graph)}")
output_graph_path = f'{OUTPUT_DIR_PATH}{test_file_name}.result.ttl'
output_graph_uri = f'https://amr.tetras-libre.fr/rdf/{test_file_name}/result'
print(f'\n -- Serialize test graph to {output_graph_path}')
graph.serialize(destination=output_graph_path,
format='turtle',
base=output_graph_uri)
#==============================================================================
# Development Test
#==============================================================================
def test_search_pattern_1(graph):
query_code, pattern_set = rule_1.__search_pattern(graph)
print(f'\n ----- query code: {query_code}')
print(f'\n ----- number of selection found: {len(pattern_set)}')
for selection in pattern_set:
result_str = f'>>> '
result_str += f'{selection.property_net.n3(graph.namespace_manager)}'
result_str += f' {selection.class_net.n3(graph.namespace_manager)}'
result_str += f' {selection.phenomena_net.n3(graph.namespace_manager)}'
print(result_str)
return pattern_set
def test_search_pattern_2(graph):
query_code, pattern_set = rule_2.__search_pattern(graph)
print(f'\n ----- query code: {query_code}')
print(f'\n ----- number of selection found: {len(pattern_set)}')
for selection in pattern_set:
result_str = f'>>> '
result_str += f'{selection.property_net_core.n3(graph.namespace_manager)}'
result_str += f' {selection.property_net_arg0.n3(graph.namespace_manager)}'
result_str += f' {selection.phenomena_net.n3(graph.namespace_manager)}'
print(result_str)
return pattern_set
def test_search_operators(graph, phenomena_net_uri):
print('\n *** DEVTEST *** Search for operators')
query_code = rule_2.__property_op_pattern_query_code(graph, phenomena_net_uri, 1)
print(f' -- query code for operator 1: \n{query_code}')
result_set = rule_2.__search_property_phenomena_operator(graph, phenomena_net_uri)
print(f'\n ----- number of selection found: {len(result_set)}')
for selection in result_set:
result_str = f'>>> '
result_str += f'{selection.property_net.n3(graph.namespace_manager)}'
print(result_str)
def devtest_add_triple(graph, triple):
print(f'\n -- Adding triple in a graph')
print(f"----- Graph length before update: {len(graph)}")
print(f"----- Triple added: {triple}")
graph.add(triple)
print(f"----- Graph length after update: {len(graph)}")
#==============================================================================
# Unit Test
#==============================================================================
def test_rule_application(test_file_name, graph, rule):
print('\n -- Rule Test')
rule_label, new_triple_list = rule(graph)
print(f' ----- label: {rule_label}')
add_triples_in_graph(test_file_name, graph, new_triple_list)
#==============================================================================
# Test Script
#==============================================================================
if __name__ == '__main__':
print('\n *** Test Preparation ***')
graph_1 = load_test_graph(TEST_FILE_NAME_1)
graph_2 = load_test_graph(TEST_FILE_NAME_2)
uriref = URIRef('net:compositeClass_orbit_hasManner_conjunction-OR')
type_uriref = URIRef('net:Composite_Class_Net')
triple = (uriref, RDF.type, type_uriref)
phenomena_net_uri = 'net:phenomena_conjunction-AND_o3'
print('\n \n')
print('\n ///////////////////// Extraction Rule 1')
print('\n *** Step Test ***')
print('\n -- Step 1: Search Pattern')
pattern_set = test_search_pattern_1(graph_1)
print('\n \n')
print('\n *** Unit Test ***')
test_rule_application(TEST_FILE_NAME_1, graph_1, rule.analyze_phenomena_and_1)
print('\n \n')
print('\n ///////////////////// Extraction Rule 2')
print('\n *** Step Test ***')
print('\n -- Step 1: Search Pattern')
pattern_set = test_search_pattern_2(graph_2)
test_search_operators(graph_2, phenomena_net_uri)
print('\n \n')
print('\n *** Unit Test ***')
test_rule_application(TEST_FILE_NAME_2, graph_2, rule.analyze_phenomena_and_2)
print('\n \n')
print('\n *** - ***')
\ No newline at end of file
@prefix ns1: <http://amr.isi.edu/frames/ld/v1.2.2/> .
@prefix ns2: <http://amr.isi.edu/rdf/core-amr#> .
@prefix ns3: <http://amr.isi.edu/rdf/amr-terms#> .
@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/asail_odrl_sentences-10#root01> a ns2:AMR ;
ns2:has-id "asail_odrl_sentences-10" ;
ns2:has-sentence "John is obligated to reproduce and distribute the Work." ;
ns2:root <http://amr.isi.edu/amr_data/asail_odrl_sentences-10#o> .
ns1:distribute-01.ARG0 a ns1:FrameRole .
ns1:distribute-01.ARG1 a ns1:FrameRole .
ns1:obligate-01.ARG1 a ns1:FrameRole .
ns1:obligate-01.ARG2 a ns1:FrameRole .
ns1:reproduce-01.ARG0 a ns1:FrameRole .
ns1:reproduce-01.ARG1 a ns1:FrameRole .
ns3:op1 a ns2:Role .
ns3:op2 a ns2:Role .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-10#a> a ns2:and ;
ns3:op1 <http://amr.isi.edu/amr_data/asail_odrl_sentences-10#r> ;
ns3:op2 <http://amr.isi.edu/amr_data/asail_odrl_sentences-10#d> .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-10#d> a ns1:distribute-01 ;
ns1:distribute-01.ARG0 <http://amr.isi.edu/amr_data/asail_odrl_sentences-10#p> ;
ns1:distribute-01.ARG1 <http://amr.isi.edu/amr_data/asail_odrl_sentences-10#w> .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-10#o> a ns1:obligate-01 ;
ns1:obligate-01.ARG1 <http://amr.isi.edu/amr_data/asail_odrl_sentences-10#p> ;
ns1:obligate-01.ARG2 <http://amr.isi.edu/amr_data/asail_odrl_sentences-10#a> .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-10#r> a ns1:reproduce-01 ;
ns1:reproduce-01.ARG0 <http://amr.isi.edu/amr_data/asail_odrl_sentences-10#p> ;
ns1:reproduce-01.ARG1 <http://amr.isi.edu/amr_data/asail_odrl_sentences-10#w> .
<http://amr.isi.edu/entity-types#person> a ns2:NamedEntity .
ns1:distribute-01 a ns2:Frame .
ns1:obligate-01 a ns2:Frame .
ns1:reproduce-01 a ns2:Frame .
ns1:work-01 a ns2:Frame .
ns2:NamedEntity a ns2:Concept ;
rdfs:label "AMR-EntityType",
"AMR-Term" .
ns2:and a ns2:Concept .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-10#w> a ns1:work-01 .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-10#p> a <http://amr.isi.edu/entity-types#person> ;
rdfs:label "John" .
ns2:Frame a ns2:Concept ;
rdfs:label "AMR-PropBank-Frame" .
ns1:FrameRole a ns2:Role ;
rdfs:label "AMR-PropBank-Role" .
@prefix ns1: <http://amr.isi.edu/rdf/amr-terms#> .
@prefix ns2: <http://amr.isi.edu/frames/ld/v1.2.2/> .
@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/asail_odrl_sentences-11#root01> a ns3:AMR ;
ns3:has-id "asail_odrl_sentences-11" ;
ns3:has-sentence "John is obligated to reproduce the movie and the picture." ;
ns3:root <http://amr.isi.edu/amr_data/asail_odrl_sentences-11#o> .
ns2:obligate-01.ARG1 a ns2:FrameRole .
ns2:obligate-01.ARG2 a ns2:FrameRole .
ns2:reproduce-01.ARG0 a ns2:FrameRole .
ns2:reproduce-01.ARG1 a ns2:FrameRole .
ns1:op1 a ns3:Role .
ns1:op2 a ns3:Role .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-11#a> a ns3:and ;
ns1:op1 <http://amr.isi.edu/amr_data/asail_odrl_sentences-11#m> ;
ns1:op2 <http://amr.isi.edu/amr_data/asail_odrl_sentences-11#p2> .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-11#m> a ns1:movie .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-11#o> a ns2:obligate-01 ;
ns2:obligate-01.ARG1 <http://amr.isi.edu/amr_data/asail_odrl_sentences-11#p> ;
ns2:obligate-01.ARG2 <http://amr.isi.edu/amr_data/asail_odrl_sentences-11#r> .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-11#p2> a <http://amr.isi.edu/entity-types#picture> .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-11#r> a ns2:reproduce-01 ;
ns2:reproduce-01.ARG0 <http://amr.isi.edu/amr_data/asail_odrl_sentences-11#p> ;
ns2:reproduce-01.ARG1 <http://amr.isi.edu/amr_data/asail_odrl_sentences-11#a> .
<http://amr.isi.edu/entity-types#person> a ns3:NamedEntity .
<http://amr.isi.edu/entity-types#picture> a ns3:NamedEntity .
ns2:obligate-01 a ns3:Frame .
ns2:reproduce-01 a ns3:Frame .
ns1:movie a ns3:Concept .
ns3:and a ns3:Concept .
<http://amr.isi.edu/amr_data/asail_odrl_sentences-11#p> a <http://amr.isi.edu/entity-types#person> ;
rdfs:label "John" .
ns3:Frame a ns3:Concept ;
rdfs:label "AMR-PropBank-Frame" .
ns3:NamedEntity a ns3:Concept ;
rdfs:label "AMR-EntityType",
"AMR-Term" .
ns2:FrameRole a ns3:Role ;
rdfs:label "AMR-PropBank-Role" .
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment