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

Test modules refactoring

parent ccbfc09f
No related branches found
No related tags found
1 merge request!1Master
Showing
with 193 additions and 192 deletions
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: Rule to generate OWL class
#------------------------------------------------------------------------------
# Generative rule to build OWL classes
# Rule: classNet => OWL class
#==============================================================================
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
#==============================================================================
# Select Pattern: Atom / Composite Class Net
#==============================================================================
def __search_pattern_1(graph):
select_data_list = ['?class_net']
clause_list = [(f'?class_net a net:Atom_Class_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 = ['?class_net']
clause_list = [(f'?class_net a net:Composite_Class_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_class_net_list(graph):
# -- Atom Class List
atom_class_net_list = []
atom_class_set = __search_pattern_1(graph)
for selection in atom_class_set:
class_net = net.AtomClassNet(graph, uri=selection.class_net)
atom_class_net_list.append(class_net)
return atom_class_net_list
def __get_composite_class_net_list(graph):
# -- Composite Class List
composite_class_net_list = []
composite_class_set = __search_pattern_2(graph)
for selection in composite_class_set:
class_net = net.CompositeClassNet(graph, uri=selection.class_net)
composite_class_net_list.append(class_net)
return composite_class_net_list
def __get_mother_class_net_list(atom_class_net_list, composite_class_net_list):
# -- URI List
mother_class_uri_list = []
for net in composite_class_net_list:
if net.mother_class_net is not None:
mother_class_uri_list += net.mother_class_net
# -- Net List
mother_class_net_list = []
for net in (atom_class_net_list + composite_class_net_list):
if net.uri in mother_class_uri_list:
mother_class_net_list.append(net)
return mother_class_net_list
#==============================================================================
# Check Methods
#==============================================================================
def __is_class_to_generate(class_net):
check_1 = class_net.is_deprecated()
if is_instance(class_net.mother_class_net, list):
check_2 = len(class_net.mother_class_net) > 0
else:
check_2 = False
return not check_1 or check_2
#==============================================================================
# Generator Methods
#==============================================================================
def __compute_class_uri(class_net):
if isinstance(class_net.class_uri, list) and len(class_net.class_uri) > 0:
class_uri = class_net.class_uri[0]
else: # computation of class_uri
net_naming = class_net.get_attribute_first_value(class_net.naming)
class_uri = produce_uriref(class_net.support_graph, f'ext-out:{net_naming}')
return class_uri
def __get_mother_class_uri(graph, mother_class_net_uri):
mother_class_net = net.ClassNet(graph, uri=mother_class_net_uri)
return __compute_class_uri(mother_class_net)
def __define_triple(new_class_uri, relation, data):
triple_list = []
for predicat in data:
triple_list.append((new_class_uri, relation, predicat))
return triple_list
def __generate_owl_taxonomic_relation(graph, new_class_uri, net):
triple_list = []
relation = produce_uriref(graph, 'rdfs:subClassOf')
predicat = None
if net.type_id == 'Atom_Class_Net':
predicat = produce_uriref(graph, 'base-out:Out_ObjectClass')
if net.type_id == 'Composite_Class_Net':
mother_class_net_uri = net.get_attribute_first_value(net.mother_class_net)
if mother_class_net_uri is None:
predicat = produce_uriref(graph, 'base-out:Out_ObjectClass')
else :
predicat = __get_mother_class_uri(graph, mother_class_net_uri)
if predicat is not None:
triple_list.append((new_class_uri, relation, predicat))
return triple_list
def __generate_owl_triple_definition(graph, net):
triple_list = []
new_class_uri = __compute_class_uri(net)
rdf_type_uri = produce_uriref(graph, RDF.type)
triple_list += __define_triple(new_class_uri, rdf_type_uri, net.class_type)
relation = produce_uriref(graph, 'rdfs:label')
triple_list += __define_triple(new_class_uri, relation, net.class_name)
relation = produce_uriref(graph, 'base-out:fromStructure')
triple_list += __define_triple(new_class_uri, relation, net.structure)
triple_list += __generate_owl_taxonomic_relation(graph, new_class_uri, net)
return triple_list
#==============================================================================
# Main Method: analyze_phenomena_or_1
#==============================================================================
def generate_owl_class(graph):
# -- Rule Initialization
rule_label = 'generate OWL class'
rule_triple_list = []
# -- Get class net listings
atom_class_net_list = __get_atom_class_net_list(graph)
composite_class_net_list = __get_composite_class_net_list(graph)
mother_class_net_list = __get_mother_class_net_list(atom_class_net_list,
composite_class_net_list)
# -- Triple Definition for 'not deprecated class net'
for class_net in (atom_class_net_list + composite_class_net_list):
if not class_net.is_deprecated():
rule_triple_list += __generate_owl_triple_definition(graph, class_net)
# -- Triple Definition for 'mother class net'
for class_net in mother_class_net_list:
rule_triple_list += __generate_owl_triple_definition(graph, class_net)
return rule_label, rule_triple_list
\ No newline at end of file
......@@ -2,10 +2,10 @@
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: Rule to conjunctive phenomena or (rule 1)
# TENET: Rule to generate OWL property
#------------------------------------------------------------------------------
# Net Expansion AMR rule to analyse conjunctive phenomena (or)
# Rule: property(class, or_phenomena) => compositeClass
# Generative rule to build OWL properties
# Rule: propertyNet => OWL property
#==============================================================================
import rdflib
......@@ -16,8 +16,6 @@ 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
#==============================================================================
......
......@@ -202,8 +202,6 @@ phenomena_analyze_sequence_2 = ['phenomena analyze sequence (2)',
rule.analyze_phenomena_and_2]
composite_class_extraction_sequence = ['composite class extraction sequence',
rule.extract_composite_class_1,
rule.extract_composite_class_2,
rule.extract_composite_class_1,
rule.extract_composite_class_2]
......
- INFO - [TENET] Extraction Processing
- INFO -
=== Process Initialization ===
- INFO - -- Process Setting
- INFO - ----- Corpus source: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_data/amrDocuments/dev/solar-system-01/SSC-01-01.stog.amr.ttl (amr)
- INFO - ----- Base output dir: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/SolarSystemDev01_factoid.ttl
- INFO - ----- technical dir path: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/technical-data/
- INFO - ----- Ontology target (id): https://tenet.tetras-libre.fr/demo/01/
- INFO - ----- Current path: /home/lamenji/Workspace/Tetras/tenet/tenet
- DEBUG - ----- Config file: /home/lamenji/Workspace/Tetras/tenet/tenet/owl_amr_config.xml
- DEBUG -
*** Config (Full Parameters) ***
-- Base Parameters
----- config file: /home/lamenji/Workspace/Tetras/tenet/tenet/owl_amr_config.xml
----- uuid: https://tenet.tetras-libre.fr/demo/01/
----- technical base name: tenet.tetras-libre.fr_demo_01
----- source corpus: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_data/amrDocuments/dev/solar-system-01/SSC-01-01.stog.amr.ttl
----- target reference: base
----- process level: sentence
----- source type: amr
----- extraction scheme: owl_amr_scheme_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/main_tests/test_owl_output/SolarSystemDev01-20230522/SolarSystemDev01_factoid.ttl
----- output directory: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/SolarSystemDev01_factoid.ttltenet.tetras-libre.fr_demo_01-20230522/
----- sentence output directory: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/technical-data/
----- technical dir path: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/technical-data/
-- Config File Definition
----- schema file: ./structure/amr-rdf-schema.ttl
----- semantic net file: ./structure/owl-snet-schema.ttl
----- config param file: ./structure/config-parameters.ttl
----- base ontology file: ./structure/base-ontology.ttl
----- CTS file: ./scheme/owl_amr_scheme_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/main_tests/test_data/amrDocuments/dev/solar-system-01/SSC-01-01.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/main_tests/test_owl_output/SolarSystemDev01-20230522/technical-data/tenet.tetras-libre.fr_demo_01.ttl
*** - ***
- INFO -
=== Extraction Processing ===
- INFO - -- Work Structure Preparation
- DEBUG - --- Graph Initialization
- DEBUG - ----- Configuration Loading
- DEBUG - -------- RDF Schema (320)
- DEBUG - -------- Semantic Net Definition (486)
- DEBUG - -------- Config Parameter Definition (520)
- DEBUG - ----- Frame Ontology Loading
- DEBUG - -------- Base Ontology produced as output (550)
- DEBUG - --- Source Data Import
- DEBUG - ----- Sentence Loading
- DEBUG - -------- /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_data/amrDocuments/dev/solar-system-01/SSC-01-01.stog.amr.ttl (598)
- DEBUG - --- Export work graph as turtle
- DEBUG - ----- Work graph file: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/technical-data/tenet.tetras-libre.fr_demo_01-0/tenet.tetras-libre.fr_demo_01.ttl
- INFO - ----- Sentence (id): SSC-01-01
- INFO - ----- Sentence (text): The Solar System is the gravitationally bound system of the Sun and the objects that orbit it, either directly or indirectly.
- INFO - -- Loading Extraction Scheme (owl_amr_scheme_1)
- DEBUG - ----- Step number: 3
- INFO - -- Loading Extraction Rules (amr_master_rule/*)
- DEBUG - ----- Total rule number: 87
- INFO - -- Applying extraction step: preprocessing
- INFO - --- *** November Transduction *** Sequence: amrld-correcting-sequence
- INFO - ----- fix-amr-bug-about-system-solar-planet: 5/5 new triples (603, 0:00:00.038906)
- INFO - --- *** November Transduction *** Sequence: amr-reification-sequence
- INFO - ----- reclassify-concept-1: 10/10 new triples (613, 0:00:00.172271)
- DEBUG - ----- reclassify-concept-2: 0/0 new triple (613, 0:00:00.073440)
- INFO - ----- reclassify-concept-3: 12/12 new triples (625, 0:00:00.060290)
- INFO - ----- reclassify-concept-4: 16/16 new triples (641, 0:00:00.165310)
- INFO - ----- reclassify-concept-5: 2/4 new triples (643, 0:00:00.070454)
- INFO - ----- reify-roles-as-concept: 10/10 new triples (653, 0:00:00.067752)
- INFO - ----- reclassify-existing-variable: 45/45 new triples (698, 0:00:00.037598)
- INFO - ----- add-new-variable-for-reified-concept: 8/8 new triples (706, 0:00:00.065261)
- INFO - ----- add-amr-leaf-for-reclassified-concept: 33/33 new triples (739, 0:00:00.048679)
- INFO - ----- add-amr-leaf-for-reified-concept: 8/8 new triples (747, 0:00:00.035066)
- INFO - ----- add-amr-edge-for-core-relation: 27/27 new triples (774, 0:00:00.123982)
- INFO - ----- add-amr-edge-for-reified-concept: 12/12 new triples (786, 0:00:00.144842)
- INFO - ----- add-amr-edge-for-name-relation: 5/5 new triples (791, 0:00:00.109103)
- DEBUG - ----- add-value-for-quant-relation: 0/0 new triple (791, 0:00:00.105128)
- INFO - ----- add-amr-edge-for-polarity-relation: 5/5 new triples (796, 0:00:00.079822)
- INFO - ----- update-amr-edge-role-1: 15/15 new triples (811, 0:00:00.086513)
- INFO - ----- add-amr-root: 5/5 new triples (816, 0:00:00.028574)
- DEBUG - --- Serializing graph to tenet.tetras-libre.fr_demo_01_preprocessing
- DEBUG - ----- step: preprocessing
- DEBUG - ----- id: https://tenet.tetras-libre.fr/demo/01/
- DEBUG - ----- work_file: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/technical-data/tenet.tetras-libre.fr_demo_01-0/tenet.tetras-libre.fr_demo_01_preprocessing.ttl
- DEBUG - ----- base: http://https://tenet.tetras-libre.fr/demo/01//preprocessing
- INFO - ----- 218 triples extracted during preprocessing step
- INFO - -- Applying extraction step: transduction
- INFO - --- *** February Transduction *** Sequence: atomic extraction sequence
- INFO - ----- extract atom classes: 30/30 new triples (846, 0:00:00.153211)
- INFO - ----- extract atom individuals: 8/8 new triples (854, 0:00:00.052523)
- INFO - ----- extract atomic properties: 75/75 new triples (929, 0:00:00.221403)
- INFO - ----- extract atom values: 10/10 new triples (939, 0:00:00.053987)
- INFO - ----- extract atom phenomena: 14/14 new triples (953, 0:00:00.066765)
- INFO - ----- propagate atom relations: 24/68 new triples (977, 0:00:01.110437)
- INFO - --- *** February Transduction *** Sequence: classification sequence (1)
- DEBUG - ----- classify modality phenomena: 0/0 new triple (977, 0:00:00.024124)
- INFO - ----- reclassify argument property to class: 11/14 new triples (988, 0:00:00.079487)
- INFO - --- *** February Transduction *** Sequence: phenomena analyze sequence (1)
- INFO - ----- analyze "polarity" phenomena (1): 32/36 new triples (1020, 0:00:00.107824)
- DEBUG - ----- analyze "polarity" phenomena (2): 0/0 new triple (1020, 0:00:00.016232)
- DEBUG - ----- analyze "polarity" phenomena (3): 0/0 new triple (1020, 0:00:00.020851)
- DEBUG - ----- analyze "polarity" phenomena (4): 0/0 new triple (1020, 0:00:00.127024)
- DEBUG - ----- analyze "polarity" phenomena (5): 0/0 new triple (1020, 0:00:00.045304)
- DEBUG - ----- analyze modifier phenomena (mod): 0/0 new triple (1020, 0:00:00.010708)
- DEBUG - ----- classify modality phenomena: 0/0 new triple (1020, 0:00:00.023176)
- INFO - --- *** February Transduction *** Sequence: phenomena analyze sequence (2)
- INFO - ----- analyze "or" phenomena (1): 1/1 new triple (1021, 0:00:00.072791)
- INFO - ----- analyze "or" phenomena (2): 55/82 new triples (1076, 0:00:00.317714)
- INFO - ----- analyze "and" phenomena (1): 2/14 new triples (1078, 0:00:00.110901)
- DEBUG - ----- analyze "and" phenomena (2): 0/0 new triple (1078, 0:00:00.014251)
- INFO - --- *** February Transduction *** Sequence: composite class extraction sequence
- INFO - ----- extract composite classes (1): 127/133 new triples (1205, 0:00:00.422208)
- DEBUG - ----- extract composite classes (2): 0/0 new triple (1205, 0:00:00.026013)
- DEBUG - ----- extract composite classes (1): 0/0 new triple (1205, 0:00:00.035889)
- DEBUG - ----- extract composite classes (2): 0/0 new triple (1205, 0:00:00.039449)
- DEBUG - --- Serializing graph to tenet.tetras-libre.fr_demo_01_transduction
- DEBUG - ----- step: transduction
- DEBUG - ----- id: https://tenet.tetras-libre.fr/demo/01/
- DEBUG - ----- work_file: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/technical-data/tenet.tetras-libre.fr_demo_01-0/tenet.tetras-libre.fr_demo_01_transduction.ttl
- DEBUG - ----- base: http://https://tenet.tetras-libre.fr/demo/01//transduction
- INFO - ----- 389 triples extracted during transduction step
- INFO - -- Applying extraction step: generation
- INFO - --- *** November Transduction *** Sequence: main-generation-sequence
- INFO - ----- compute-uri-for-owl-declaration-1: 1/1 new triple (1206, 0:00:00.031373)
- INFO - ----- compute-uri-for-owl-declaration-2: 3/3 new triples (1209, 0:00:00.027419)
- INFO - ----- compute-uri-for-owl-declaration-3: 1/1 new triple (1210, 0:00:00.032014)
- DEBUG - ----- compute-uri-for-owl-declaration-4: 0/0 new triple (1210, 0:00:00.020375)
- INFO - ----- compute-uri-for-owl-declaration-5: 4/4 new triples (1214, 0:00:00.025519)
- INFO - ----- compute-uri-for-owl-declaration-6: 4/4 new triples (1218, 0:00:00.029204)
- INFO - ----- compute-uri-for-owl-declaration-7: 1/1 new triple (1219, 0:00:00.020973)
- INFO - ----- generate-atom-class: 12/12 new triples (1231, 0:00:00.009573)
- DEBUG - ----- classify-atom-class-1: 0/0 new triple (1231, 0:00:00.012281)
- INFO - ----- classify-atom-class-2: 4/4 new triples (1235, 0:00:00.016338)
- INFO - ----- generate-individual: 3/3 new triples (1238, 0:00:00.009752)
- DEBUG - ----- classify-individual-1: 0/0 new triple (1238, 0:00:00.008055)
- DEBUG - ----- classify-individual-2: 0/0 new triple (1238, 0:00:00.012234)
- INFO - ----- generate-atom-property-1: 20/20 new triples (1258, 0:00:00.011682)
- INFO - ----- generate-atom-property-12: 16/16 new triples (1274, 0:00:00.012070)
- DEBUG - ----- generate-inverse-relation: 0/0 new triple (1274, 0:00:00.011165)
- DEBUG - ----- generate-composite-class: 0/0 new triple (1274, 0:00:00.011323)
- DEBUG - ----- add-restriction-to-class-1: 0/0 new triple (1274, 0:00:00.022630)
- DEBUG - ----- add-restriction-to-class-2: 0/0 new triple (1274, 0:00:00.014546)
- DEBUG - ----- add-restriction-to-class-3: 0/0 new triple (1274, 0:00:00.015878)
- DEBUG - ----- add-restriction-to-class-4: 0/0 new triple (1274, 0:00:00.018158)
- DEBUG - ----- add-restriction-to-class-5: 0/0 new triple (1274, 0:00:00.016311)
- DEBUG - ----- add-restriction-to-class-6: 0/0 new triple (1274, 0:00:00.015513)
- INFO - --- *** February Transduction *** Sequence: property_generation_sequence
- INFO - ----- generate OWL property: 9/29 new triples (1283, 0:00:00.347900)
- DEBUG - --- Serializing graph to tenet.tetras-libre.fr_demo_01_generation
- DEBUG - ----- step: generation
- DEBUG - ----- id: https://tenet.tetras-libre.fr/demo/01/
- DEBUG - ----- work_file: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/technical-data/tenet.tetras-libre.fr_demo_01-0/tenet.tetras-libre.fr_demo_01_generation.ttl
- DEBUG - ----- base: http://https://tenet.tetras-libre.fr/demo/01//generation
- INFO - ----- 78 triples extracted during generation step
- DEBUG - --- Serializing graph to factoid file (/home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/technical-data/tenet.tetras-libre.fr_demo_01-0/tenet.tetras-libre.fr_demo_01_factoid.ttl)
- DEBUG - ----- Number of factoids: 98
- DEBUG - ----- Graph base: http://https://tenet.tetras-libre.fr/demo/01//factoid
- INFO -
=== Final Ontology Generation ===
- INFO - -- Making complete factoid graph by merging the result factoids
- INFO - ----- Total factoid number: 98
- INFO - -- Serializing graph to factoid string
- INFO - ----- Graph base: http://https://tenet.tetras-libre.fr/demo/01//factoid
- INFO - -- Serializing graph to factoid file
- INFO - ----- Ontology Turtle File: /home/lamenji/Workspace/Tetras/tenet/tests/main_tests/test_owl_output/SolarSystemDev01-20230522/SolarSystemDev01_factoid.ttl
- INFO -
=== Done ===
- INFO -
*** Execution Time ***
----- Function: create_ontology_from_amrld_file (tenet.main)
----- Total Time: 0:00:05.934835
----- Process Time: 0:00:05.758003
*** - ***
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment