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

Update tenet.main module (fix minor technical bug)

parent 77fe27f0
Branches
Tags
No related merge requests found
Showing
with 171 additions and 35 deletions
......@@ -8,4 +8,4 @@ sys.path.insert(0, os.path.abspath(LIB_PATH))
# -- Main Methods
from main import create_ontology_from_amrld_file
from main import create_ontology_from_amrld_dir
#from .main import create_ontology_from_unlrdf_file
\ No newline at end of file
#from main import create_ontology_from_unlrdf_file
\ No newline at end of file
from .pattern import Pattern
\ No newline at end of file
from febTransduction.pattern import Pattern
from .semantic_net_rdf_reference import SemanticNetReferenceHandle
from febTransduction.semantic_net_rdf_reference import SemanticNetReferenceHandle
from .net import Net
from febTransduction.net.net import Net
from .class_net import ClassNet
from .atom_class_net import AtomClassNet
from .composite_class_net import CompositeClassNet
from febTransduction.net.class_net import ClassNet
from febTransduction.net.atom_class_net import AtomClassNet
from febTransduction.net.composite_class_net import CompositeClassNet
from .property_net import PropertyNet
from .atom_property_net import AtomPropertyNet
from .composite_property_net import CompositePropertyNet
from febTransduction.net.property_net import PropertyNet
from febTransduction.net.atom_property_net import AtomPropertyNet
from febTransduction.net.composite_property_net import CompositePropertyNet
from .individual_net import IndividualNet
from febTransduction.net.individual_net import IndividualNet
from .value_net import ValueNet
from febTransduction.net.value_net import ValueNet
from .phenomena_net import PhenomenaNet
from febTransduction.net.phenomena_net import PhenomenaNet
from .restriction_net import RestrictionNet
from febTransduction.net.restriction_net import RestrictionNet
......@@ -18,7 +18,7 @@ from rdflib.namespace import NamespaceManager
import febTransduction.query_builder as query_builder
import febTransduction.net as net
from febTransduction.net.semantic_net_rdf_reference import SemanticNetReferenceHandle
from febTransduction.semantic_net_rdf_reference import SemanticNetReferenceHandle
#==============================================================================
......
......@@ -29,7 +29,7 @@ logger = logging.getLogger('root')
# Steps
#==============================================================================
def set_config(source_type, source_corpus, onto_prefix,
def __set_config(source_type, source_corpus, onto_prefix,
base_output_dir, technical_dir_path):
logger.info("-- Process Setting ")
......@@ -54,26 +54,23 @@ def set_config(source_type, source_corpus, onto_prefix,
return process_config
def init_process(config):
# logger.info("-- Creating output target directory: " + config.output_dir)
# os.makedirs(config.output_dir, exist_ok=True)
def __count_number_of_graph(config):
logger.debug("-- Counting number of graph files (sentences) ")
sentence_count = 0
for file_ref in glob.glob(config.source_sentence_file, recursive = True):
sentence_count += 1
logger.debug("----- Graph count: {0}".format(sentence_count))
assert sentence_count > 0, f'no file to analyze in the input directory ({config.source_sentence_file})'
logger.info("----- Number of Graphs: {0}".format(sentence_count))
def apply_extraction(config, sentence_file):
def __apply_extraction(config, sentence_file):
os.makedirs(config.sentence_output_dir, exist_ok=True)
work_graph = structure.prepare_sentence_work(config, sentence_file)
_, new_triple_list = process.apply(config, work_graph)
return new_triple_list
def generate_final_ontology(result_triple_list):
def __generate_final_ontology(result_triple_list):
config.sentence_output_dir = ''
logger.info("-- Making complete factoid graph by merging the result factoids")
factoid_graph = Graph()
......@@ -83,7 +80,7 @@ def generate_final_ontology(result_triple_list):
return factoid_graph
def serialize_factoid_graph(config, factoid_graph, out_file_path=None):
def __serialize_factoid_graph(config, factoid_graph, out_file_path=None):
logger.info('-- Serializing graph to factoid string')
base_ref = f'http://{config.uuid_str}/factoid'
......@@ -131,19 +128,19 @@ def create_ontology_from_amrld_file(amrld_file_path,
# -- Process Initialization
logger.info('\n === Process Initialization === ')
if onto_prefix is None: onto_prefix = 'DefaultId'
config = set_config('amr', amrld_file_path, onto_prefix,
config = __set_config('amr', amrld_file_path, onto_prefix,
out_file_path, technical_dir_path)
init_process(config)
assert os.path.exists(amrld_file_path), f'input file does not exists ({amrld_file_path})'
# -- Extraction Processing
logger.info('\n === Extraction Processing === ')
config.sentence_output_dir = f'-0'
result_triple_list = apply_extraction(config, amrld_file_path)
result_triple_list = __apply_extraction(config, amrld_file_path)
# -- Final Ontology Generation (factoid_graph)
logger.info('\n === Final Ontology Generation === ')
factoid_graph = generate_final_ontology(result_triple_list)
ontology_turtle_string = serialize_factoid_graph(config, factoid_graph, out_file_path)
factoid_graph = __generate_final_ontology(result_triple_list)
ontology_turtle_string = __serialize_factoid_graph(config, factoid_graph, out_file_path)
# -- Done
logger.info('\n === Done === ')
......@@ -185,9 +182,10 @@ def create_ontology_from_amrld_dir(amrld_dir_path,
# -- Process Initialization
logger.info('\n === Process Initialization === ')
if onto_prefix is None: onto_prefix = 'DefaultId'
config = set_config('amr', amrld_dir_path, onto_prefix,
config = __set_config('amr', amrld_dir_path, onto_prefix,
out_file_path, technical_dir_path)
init_process(config)
assert os.path.exists(amrld_dir_path), f'input directory does not exists ({amrld_dir_path})'
__count_number_of_graph(config)
# -- Extraction Processing
logger.info('\n === Extraction Processing === ')
......@@ -198,13 +196,13 @@ def create_ontology_from_amrld_dir(amrld_dir_path,
sentence_count += 1
logger.info(f' *** sentence {sentence_count} *** ')
config.sentence_output_dir = f'-{sentence_count}'
new_triple_list = apply_extraction(config, sentence_file)
new_triple_list = __apply_extraction(config, sentence_file)
result_triple_list.extend(new_triple_list)
# -- Final Ontology Generation (factoid_graph)
logger.info('\n === Final Ontology Generation === ')
factoid_graph = generate_final_ontology(result_triple_list)
ontology_turtle_string = serialize_factoid_graph(config, factoid_graph, out_file_path)
factoid_graph = __generate_final_ontology(result_triple_list)
ontology_turtle_string = __serialize_factoid_graph(config, factoid_graph, out_file_path)
# -- Done
logger.info('\n === Done === ')
......
@base <http://SolarSystemDev01/factoid> .
@prefix ns1: <https://tenet.tetras-libre.fr/semantic-net#> .
@prefix ns2: <https://tenet.tetras-libre.fr/base-ontology#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
ns1:atomClass_gravitation_g ns1:hasClassURI <https://tenet.tetras-libre.fr/extract-result#gravitation> .
ns1:atomClass_object_o ns1:hasClassURI <https://tenet.tetras-libre.fr/extract-result#object> .
ns1:atomClass_sun_s2 ns1:hasClassURI <https://tenet.tetras-libre.fr/extract-result#sun> .
ns1:atomClass_system_p ns1:hasClassURI <https://tenet.tetras-libre.fr/extract-result#system> .
ns1:atomClass_system_s ns1:hasClassURI <https://tenet.tetras-libre.fr/extract-result#system> .
ns1:atomProperty_bind_b ns1:hasProperty12URI <https://tenet.tetras-libre.fr/extract-result#bind-of> ;
ns1:hasPropertyURI <https://tenet.tetras-libre.fr/extract-result#bind> .
ns1:atomProperty_direct_d ns1:hasProperty12URI <https://tenet.tetras-libre.fr/extract-result#direct-of> ;
ns1:hasPropertyURI <https://tenet.tetras-libre.fr/extract-result#direct> .
ns1:atomProperty_direct_d2 ns1:hasProperty12URI <https://tenet.tetras-libre.fr/extract-result#direct-of> ;
ns1:hasPropertyURI <https://tenet.tetras-libre.fr/extract-result#direct> .
ns1:atomProperty_hasManner_m9 ns1:hasProperty12URI <https://tenet.tetras-libre.fr/extract-result#hasManner> ;
ns1:hasPropertyURI <https://tenet.tetras-libre.fr/extract-result#hasManner> .
ns1:atomProperty_hasPart_p9 ns1:hasProperty12URI <https://tenet.tetras-libre.fr/extract-result#hasPart> ;
ns1:hasPropertyURI <https://tenet.tetras-libre.fr/extract-result#hasPart> .
ns1:compositeClass_gravitation-binding-system-hasPart-sun-and-object_g ns1:hasClassURI <https://tenet.tetras-libre.fr/extract-result#gravitation-binding-system-hasPart-sun-and-object> .
ns1:compositeClass_system-hasPart-sun-and-object-hasPart-object_s ns1:hasClassURI <https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object-hasPart-object> .
ns1:compositeClass_system-hasPart-sun-and-object-hasPart-sun_s ns1:hasClassURI <https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object-hasPart-sun> .
ns1:compositeClass_system-hasPart-sun-and-object_s ns1:hasClassURI <https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object> .
ns1:compositeProperty_not-direct_d2 ns1:hasPropertyURI <https://tenet.tetras-libre.fr/extract-result#not-direct> .
ns1:individual_system_SolarSystem ns1:hasIndividualURI <https://tenet.tetras-libre.fr/extract-result#solar-system> .
<https://tenet.tetras-libre.fr/extract-result#bind> a owl:ObjectProperty ;
rdfs:label "bind" ;
rdfs:subPropertyOf ns2:Out_ObjectProperty ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#gravitation-binding-system-hasPart-sun-and-object> a owl:Class ;
rdfs:label "gravitation-binding-system-hasPart-sun-and-object" ;
rdfs:subClassOf [ a owl:Restriction ;
owl:onProperty <https://tenet.tetras-libre.fr/extract-result#bind-of> ;
owl:someValuesFrom <https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object> ],
<https://tenet.tetras-libre.fr/extract-result#gravitation> ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#solar-system> a owl:individual,
<https://tenet.tetras-libre.fr/extract-result#system>,
<https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object>,
<https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object-hasPart-object>,
<https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object-hasPart-sun> ;
rdfs:label "Solar System" ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#bind-of> a owl:ObjectProperty ;
rdfs:label "bind-of" ;
rdfs:subPropertyOf ns2:Out_ObjectProperty ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#direct> a owl:ObjectProperty ;
rdfs:label "direct" ;
rdfs:subPropertyOf ns2:Out_ObjectProperty ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#direct-of> a owl:ObjectProperty ;
rdfs:label "direct-of" ;
rdfs:subPropertyOf ns2:Out_ObjectProperty ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#gravitation> a owl:Class ;
rdfs:label "gravitation" ;
rdfs:subClassOf ns2:Entity ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#hasManner> a owl:ObjectProperty ;
rdfs:label "hasManner" ;
rdfs:subPropertyOf ns2:Out_ObjectProperty ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object-hasPart-object> a owl:Class ;
rdfs:label "system-hasPart-sun-and-object-hasPart-object" ;
rdfs:subClassOf [ a owl:Restriction ;
owl:onProperty <https://tenet.tetras-libre.fr/extract-result#hasPart> ;
owl:someValuesFrom <https://tenet.tetras-libre.fr/extract-result#object> ],
<https://tenet.tetras-libre.fr/extract-result#system>,
<https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object> ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object-hasPart-sun> a owl:Class ;
rdfs:label "system-hasPart-sun-and-object-hasPart-sun" ;
rdfs:subClassOf [ a owl:Restriction ;
owl:onProperty <https://tenet.tetras-libre.fr/extract-result#hasPart> ;
owl:someValuesFrom <https://tenet.tetras-libre.fr/extract-result#sun> ],
<https://tenet.tetras-libre.fr/extract-result#system>,
<https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object> ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#object> a owl:Class ;
rdfs:label "object" ;
rdfs:subClassOf ns2:Entity ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#sun> a owl:Class ;
rdfs:label "sun" ;
rdfs:subClassOf ns2:Entity ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#system-hasPart-sun-and-object> a owl:Class ;
rdfs:label "system-hasPart-sun-and-object" ;
rdfs:subClassOf [ a owl:Restriction ;
owl:onProperty <https://tenet.tetras-libre.fr/extract-result#hasPart> ;
owl:someValuesFrom <https://tenet.tetras-libre.fr/extract-result#sun> ],
[ a owl:Restriction ;
owl:onProperty <https://tenet.tetras-libre.fr/extract-result#hasPart> ;
owl:someValuesFrom <https://tenet.tetras-libre.fr/extract-result#object> ],
<https://tenet.tetras-libre.fr/extract-result#system> ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#hasPart> a owl:ObjectProperty ;
rdfs:label "hasPart" ;
rdfs:subPropertyOf ns2:Out_ObjectProperty ;
ns2:fromStructure "SSC-01-01" .
<https://tenet.tetras-libre.fr/extract-result#system> a owl:Class ;
rdfs:label "system" ;
rdfs:subClassOf ns2:Entity ;
ns2:fromStructure "SSC-01-01" .
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment