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

Update script extract to generate a full graph as turtle

parent d5d7a35a
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# Importing required modules # Importing required modules
#============================================================================== #==============================================================================
import glob
from rdflib import Graph from rdflib import Graph
...@@ -26,16 +27,19 @@ CORPUS_DIR = "corpus/" ...@@ -26,16 +27,19 @@ CORPUS_DIR = "corpus/"
CTS_DIR = "cts/" CTS_DIR = "cts/"
# Config Definition # Config Definition
dash_file = "http://datashapes.org/dash.ttl"
schema_file = "unl-rdf-schema.ttl" schema_file = "unl-rdf-schema.ttl"
semantic_net_file = "semantic-net.ttl" semantic_net_file = "semantic-net.ttl"
cts_file = "transduction-schemes.ttl"
c_param_file = "config-parameters.ttl" c_param_file = "config-parameters.ttl"
req_onto_file = "requirement-ontology.ttl" req_onto_file = "requirement-ontology.ttl"
sys_onto_file = "system-ontology.ttl" sys_onto_file = "system-ontology.ttl"
f_param_file = "ontology-parameters.ttl" f_param_file = "ontology-parameters.ttl"
# Dev Tests # Dev Tests
corpus = "CCTP-SRSA-IP-20210625/" base_uri = "https://unsel.tetras-libre.fr/tenet/working"
req_300_file = "SRSA-IP_STB_PHON_00300.ttl" corpus = "CCTP-SRSA-IP-20210831/"
req_file = "SRSA-IP_STB_PHON_00100.ttl"
#============================================================================== #==============================================================================
...@@ -63,6 +67,10 @@ def load_config(g): ...@@ -63,6 +67,10 @@ def load_config(g):
g.parse(file_ref) g.parse(file_ref)
print("----- Semantic Net Definition (" + str(len(g)) + ")") print("----- Semantic Net Definition (" + str(len(g)) + ")")
file_ref = dash_file
g.parse(file_ref)
print("----- Data Shapes Dash (" + str(len(g)) + ")")
file_ref = CONFIG_DIR + c_param_file file_ref = CONFIG_DIR + c_param_file
g.parse(file_ref) g.parse(file_ref)
print("----- Config Parameter Definition (" + str(len(g)) + ")") print("----- Config Parameter Definition (" + str(len(g)) + ")")
...@@ -84,119 +92,39 @@ def load_frame(g): ...@@ -84,119 +92,39 @@ def load_frame(g):
print("----- Ontology Parameters (" + str(len(g)) + ")") print("----- Ontology Parameters (" + str(len(g)) + ")")
def load_sentence(g, sentence_file): def load_sentences(g):
print("-- Sentence Loading:") print("-- Sentence Loading:")
file_ref = CORPUS_DIR + corpus + sentence_file #file_ref = CORPUS_DIR + corpus + sentence_file
target_ref = CORPUS_DIR + corpus + '**/*.ttl'
for file_ref in glob.glob(target_ref, recursive = True):
g.parse(file_ref) g.parse(file_ref)
print("----- " + sentence_file + " (" + str(len(g)) + ")") print("----- " + file_ref + " (" + str(len(g)) + ")")
#==============================================================================
# Graph Preprocessing
#==============================================================================
def bypass_reification(g):
print("-- Bypass Reification:")
cts_group = "preprocessing/reification/"
queryString = read_query(cts_group, 201)
g.update(queryString)
print("----- update to extend UNL relation (" + str(len(g)) + ")")
queryString = read_query(cts_group, 202)
g.update(queryString)
print("----- update to bypass scopes (" + str(len(g)) + ")")
#============================================================================== #==============================================================================
# Net Extension (CTS Application) # CT Schemes for Transduction Process
#============================================================================== #==============================================================================
def extract_entity(g): def load_cts(g):
print("-- Net Extension to Extract Entity:") print("-- CTS Loading:")
cts_group = "net_extension/entity_extraction/"
queryString = read_query(cts_group, 301) file_ref = CONFIG_DIR + cts_file
g.update(queryString) g.parse(file_ref)
print("----- update to create Entity net (" + str(len(g)) + ")") print("----- All Schemes (" + str(len(g)) + ")")
print("-------- net instances: ")
for r in g.query(read_query("selection/", 101)):
print("-------- " + f"{r.net} ")
queryString = read_query(cts_group, 302)
g.update(queryString)
print("----- update to create Entity net (" + str(len(g)) + ")")
print("-------- net instances: ")
for r in g.query(read_query("selection/", 101)):
print("-------- " + f"{r.net} ")
queryString = read_query(cts_group, 303)
g.update(queryString)
print("----- update to create Entity net (" + str(len(g)) + ")")
print("-------- net instances: ")
for r in g.query(read_query("selection/", 101)):
print("-------- " + f"{r.net} ")
queryString = read_query(cts_group, 304)
g.update(queryString)
print("----- update to create Entity net (" + str(len(g)) + ")")
print("-------- net instances: ")
for r in g.query(read_query("selection/", 101)):
print("-------- " + f"{r.net} ")
queryString = read_query(cts_group, 305)
g.update(queryString)
print("----- update to create Entity net (" + str(len(g)) + ")")
print("-------- net instances: ")
for r in g.query(read_query("selection/", 101)):
print("-------- " + f"{r.net} ")
queryString = read_query(cts_group, 306)
g.update(queryString)
print("----- update to create Entity net (" + str(len(g)) + ")")
print("-------- net instances: ")
for r in g.query(read_query("selection/", 101)):
print("-------- " + f"{r.net} ")
queryString = read_query(cts_group, 307)
g.update(queryString)
print("----- update to create Entity net (" + str(len(g)) + ")")
print("-------- net instances: ")
for r in g.query(read_query("selection/", 101)):
print("-------- " + f"{r.net} ")
queryString = read_query(cts_group, 308)
g.update(queryString)
print("----- update to create Entity net (" + str(len(g)) + ")")
print("-------- net instances: ")
for r in g.query(read_query("selection/", 101)):
print("-------- " + f"{r.net} ")
#============================================================================== #==============================================================================
# Ontology Generation # Result (export)
#============================================================================== #==============================================================================
def classify_entity(g): def export_result(g):
print("-- Enity Classification (From Net Ontology to System Ontology):") export_file = 'output.ttl'
cts_group = "generation/classification/" print("-- Export result as turtle: " + export_file)
g.serialize(destination=export_file, base=base_uri, format='turtle')
queryString = read_query(cts_group, 401)
g.update(queryString)
print("----- update to create Entity net (" + str(len(g)) + ")")
print("-------- entity classes: ")
for r in g.query(read_query("selection/", 102)):
print("-------- " + f"{r.entity}")
queryString = read_query(cts_group, 402)
g.update(queryString)
print("----- update to create Entity net (" + str(len(g)) + ")")
print("-------- entity classes: ")
for r in g.query(read_query("selection/", 102)):
print("-------- " + f"{r.entity}")
#============================================================================== #==============================================================================
...@@ -211,16 +139,15 @@ def run(): ...@@ -211,16 +139,15 @@ def run():
g = Graph() g = Graph()
load_config(g) load_config(g)
load_frame(g) load_frame(g)
load_sentence(g, req_300_file)
print("\n" + "- Graph Preprocessing") print("\n" + "- Preparation of Transduction Process")
bypass_reification(g) load_cts(g)
print("\n" + "- Net Extension (CTS Application)") print("\n" + "- Data Source Imports")
extract_entity(g) load_sentences(g)
print("\n" + "- Ontology Generation ") print("\n" + "- Result")
classify_entity(g) export_result(g)
except: except:
print("!!! An exception occurred !!!") print("!!! An exception occurred !!!")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment