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

Lib update (structure, inference) in spec2B

parent e0f8db10
No related tags found
No related merge requests found
Showing
with 1011 additions and 44 deletions
......@@ -11,3 +11,5 @@ corpus/COMP*
output*.ttl
output/*
tenet-env/*
venv/*
.idea*
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/python3.5
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*
#==============================================================================
......@@ -18,15 +18,15 @@ from lib import structure
# Parameters
#==============================================================================
# Dev Tests
base_uri = "https://unsel.tetras-libre.fr/tenet/working"
#base_uri = "https://unsel.tetras-libre.fr/tenet/working"
corpus_40 = "CCTP-SRSA-IP-20210831/"
req_100 = "CCTP-SRSA-IP-20210831-R100/"
req_200 = "CCTP-SRSA-IP-20210831-R200/"
req_300 = "CCTP-SRSA-IP-20210831-R300/"
req_1100 = "CCTP-SRSA-IP-20210831-R1100/"
req_13900 = "CCTP-SRSA-IP-20210831-R13900/"
req_vincent = "Temp/"
corpus_comp = "COMP/"
req_f1 = "COMP/F1/"
req_34 = "COMP/34/"
......@@ -40,27 +40,29 @@ corpus_RAILWAY = "Railway/"
# Process
#==============================================================================
#target_ref = "system"
target_ref = "system"
#target_ref = "environment"
target_ref = "railway"
#target_ref = "railway"
#structure.create(corpus_comp, 'COMP-01', target_ref)
#structure.create(req_f1, 'C-F1', target_ref)
#structure.create(req_50, 'C-50', target_ref)
#structure.create(req_34, 'C-34', target_ref)
#structure.create_extraction_graph(corpus_comp, 'COMP-01', target_ref)
#structure.create_extraction_graph(req_f1, 'C-F1', target_ref)
#structure.create_extraction_graph(req_50, 'C-50', target_ref)
#structure.create_extraction_graph(req_34, 'C-34', target_ref)
#structure.create(req_13900, 'R13900', target_ref)
structure.create(req_100, 'R100f', target_ref)
#structure.create(req_200, 'R200f', target_ref)
#structure.create(req_300, 'R300f', target_ref)
#structure.create(req_1100, 'R1100f', target_ref)
#structure.create_extraction_graph(req_13900, 'R13900', target_ref)
structure.create_extraction_graph(req_100, 'R100f', target_ref)
#structure.create_extraction_graph(req_200, 'R200f', target_ref)
#structure.create_extraction_graph(req_300, 'R300f', target_ref)
#structure.create_extraction_graph(req_1100, 'R1100f', target_ref)
#structure.create(corpus_40, 'Corpus-CCTP-40f', target_ref)
#structure.create_extraction_graph(corpus_40, 'Corpus-CCTP-40f', target_ref)
#structure.create(corpus_ERTMS, 'Corpus-ERTMS', target_ref)
#structure.create(corpus_PEV, 'Corpus-PEV', target_ref)
#structure.create_extraction_graph(corpus_ERTMS, 'Corpus-ERTMS', target_ref)
#structure.create_extraction_graph(corpus_PEV, 'Corpus-PEV', target_ref)
#structure.create(corpus_RAILWAY, 'corpus-Railway', target_ref)
structure.create_extraction_graph(corpus_RAILWAY, 'corpus-Railway', target_ref)
#structure.create(req_vincent, 'temp', target_ref)
......
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*
#==============================================================================
# TENET: inference
#------------------------------------------------------------------------------
# Work structure for extraction processing.
#==============================================================================
#==============================================================================
# Importing required modules
#==============================================================================
from subprocess import Popen, PIPE, STDOUT
from rdflib import Graph, Namespace, URIRef
#######################################################################################################
#==============================================================================
# Parameters
#######################################################################################################
#==============================================================================
shaclBase = 'shacl-1.3.2/bin'
#######################################################################################################
#==============================================================================
# Inference Run
#######################################################################################################
#==============================================================================
def run_command(cmd):
with Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) as p:
......@@ -35,9 +49,9 @@ def shaclInfer(ttlPath, mode, ttlRulesPath = ''):
#######################################################################################################
#==============================================================================
# Inference Step
#######################################################################################################
#==============================================================================
clearExecutionInstances = """
PREFIX cts: <https://unsel.tetras-libre.fr/tenet/transduction-schemes#>
......@@ -60,21 +74,41 @@ addExecutionInstance = """
"""
def applyInferStep(uuidStr, graph, step):
def apply_step(uuidStr, graph, step):
try:
print("-- Apply inference step: " + step)
print("\n" + "-- Preparation")
step_ref = "cts:" + step
dest_file = uuidStr + '-' + step + ".ttl"
print("[DEV] destfile = " + dest_file)
base_ref = "http://" + uuidStr + '/' + step
print("-- destfile = " + dest_file)
work_file = dest_file
print("-- workfile = " + work_file)
print("\n" + "--- Graph Initialization")
graph.update(clearExecutionInstances)
graph.update(addExecutionInstance.format(step_ref)) # ex. : step = 'cts:generation'
graph.serialize(destination=dest_file, base=base_ref, format='turtle') # serialize graph before inference
work_file = dest_file
print("[DEV] workfile = " + work_file)
graph.serialize(destination=dest_file, base=base_ref, format='turtle')
print("\n" + "- Apply SHACL inference in work graph")
inferResult = shaclInfer(work_file, 'infer') # apply SHACL inference
graph.parse(data=inferResult) # update graph with inference
graph.serialize(destination=dest_file, base=base_ref, format='turtle') # serialize graph after inference
print("\n" + "- Update dest graph with inference")
graph.parse(data=inferResult)
graph.serialize(destination=dest_file, base=base_ref, format='turtle')
print("\n" + "- Result")
return graph, inferResult
except:
print("!!! An exception occurred !!!")
#==============================================================================
# Main Function
#==============================================================================
#==============================================================================
# Execution
......@@ -82,17 +116,20 @@ def applyInferStep(uuidStr, graph, step):
if __name__ == '__main__':
uuidStr = "test"
output = "result-graph.ttl"
print("\n" + "[Tenet] Apply inferences")
uuidStr = "test/test"
output = "test/result-graph.ttl"
# -- Working Graph
graph = Graph()
graph.parse("starting-graph.ttl")
graph.parse("test/starting-graph.ttl")
# -- Extraction
#graph, _ = applyInferStep(uuidStr, graph, 'preprocessing')
#graph, _ = applyInferStep(uuidStr, graph, 'net_extension')
graph, finalInferResult = applyInferStep(uuidStr, graph, 'generation_dga_patch')
graph, _ = apply_step(uuidStr, graph, 'preprocessing')
graph, _ = apply_step(uuidStr, graph, 'net_extension')
graph, finalInferResult = apply_step(uuidStr, graph, 'generation')
# -- Write result
factoidPath = uuidStr+'_factoid.ttl'
with open(factoidPath, 'w') as outfile:
......
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment