Commit 197defb6 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

shacl + ui v0.1

parent 20927d60
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -25,6 +25,7 @@
<ul *ngFor="let inf of infer;" fxLayout fxLayoutGap="15px" class="navigation-items">
<div>
<input class="btn btn-info"
[disabled] = "exporting"
type="button"
value="Inferencing"
(click)="updateInfer(inf.id)"/>
......@@ -34,6 +35,9 @@
</div>
</div>
<div [hidden] = "!showSpinner">
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</div>
<div class="mat-elevation-z8">
<table mat-table [dataSource]="newdataSource" class="mat-elevation-z8">
<!-- Position Column -->
......@@ -45,12 +49,13 @@
<!-- Name Column -->
<ng-container matColumnDef="prefix_data">
<th mat-header-cell *matHeaderCellDef> Prefix </th>
<td mat-cell *matCellDef="let element"> {{element.prefix_data}} </td>
<td mat-cell *matCellDef="let element">{{element.prefix_data}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="title_data">
<th mat-header-cell *matHeaderCellDef> Title </th>
<td mat-cell *matCellDef="let element"> {{element.title_data}} </td>
<td mat-cell *matCellDef="let element" matTooltip={{get_metrics(element.title_data)}}>{{element.title_data}} <span *ngIf="get_metrics(element.title_data).length > 0" matBadge={{get_metrics(element.title_data).length}} matBadgeColor="warn" matBadgeSize="small" position="above">&nbsp;&nbsp; </span>
</td>
</ng-container>
<ng-container matColumnDef="main_data">
......
......@@ -35,7 +35,12 @@ export class BoilerplateListComponent implements OnInit {
thenewdataSource:BoilerplateData[] = [{}];
newdataSource = new MatTableDataSource(this.thenewdataSource);
infer:InferenceResults[] = [{}];
//when inference button is pressed
showSpinner = false;
exporting = false;
num = 1
@ViewChild(MatPaginator) paginator= this.newdataSource.paginator;
......@@ -50,7 +55,7 @@ export class BoilerplateListComponent implements OnInit {
ngOnInit(): void {
this.retrieveBoilerplates();
this.retrieve();
this.getInfer()
this.getInfer();
}
retrieveBoilerplates(): void {
......@@ -135,13 +140,21 @@ export class BoilerplateListComponent implements OnInit {
}
updateInfer(id: any): void {
this.showSpinner = !this.showSpinner;
this.exporting = !this.exporting
this.boilerplateService.inferUpdate(this.route.snapshot.params.gb, id, this.currentInfer)
.subscribe(
data => {
console.log(data);
this.currentInfer = data[0];
//this.infer = data;
this.showSpinner = !this.showSpinner;
this.exporting = !this.exporting;
location.reload();
},
error => {
console.log(error);
this.showSpinner = !this.showSpinner;
this.exporting = !this.exporting
});
}
......@@ -150,4 +163,14 @@ export class BoilerplateListComponent implements OnInit {
this.newdataSource.filter = filterValue.trim().toLowerCase();
}
get_metrics(i:any): any {
if (this.currentInfer?.inference_data){
const obj = JSON.parse(this.currentInfer['inference_data'].replace(/'/g,"\""))
if (obj[i]){
return obj[i]
}
}
return 0
}
}
......@@ -25,7 +25,7 @@ export class GroupBoilerplate {
export class InferenceResults {
id?:any;
infer_group_of_boilerplate?: any;
inference_data?: string;
inference_data?: any;
}
export class Sections {
......
import os, subprocess, shutil
from rdflib import Graph, BNode
from rdflib.namespace import RDFS
from rdflib import ConjunctiveGraph, URIRef, RDFS, RDF, Namespace
......@@ -15,12 +16,15 @@ def getclassofmain(main):
def inferencing(project, boilerlate, prefix, main, suffix):
metrics = {}
listofboil = []
listofprefix = []
listofmain = []
listofsuffix = []
for i in boilerlate:
listofboil.append(list(i.values()))
#print(list(i.values('title'))[0]['title'])
metrics[list(i.values('title'))[0]['title']] = []
for i in prefix:
listofprefix.append(list(i.values()))
for i in main:
......@@ -28,14 +32,26 @@ def inferencing(project, boilerlate, prefix, main, suffix):
for i in suffix:
listofsuffix.append(list(i.values()))
#findclassofmain(listofmain)
exportboiltottl(project, listofprefix, listofboil, listofmain, listofsuffix)
#print(project)
#print(listofboil[0][0]['id'])
#print(listofprefix[0][0]['id'])
ontology_with_new_req = exportboiltottl(project, listofprefix, listofboil, listofmain, listofsuffix)
infer_result = shacl(ontology_with_new_req)
#find in which metrics the requirements belongs e.g. title:REQ-1 is only an Incomplete req (and Ambiguous req),
# so -> 'REQ-1' : [Incomplete] ('REQ-1' : [Incomplete, Ambiguous])
for met in infer_result:
for title in metrics:
if title in infer_result[met]:
metrics[title].append(met)
metrics.update(infer_result)
return metrics
def exportboiltottl(project, prefix, boilerplate, main, suffix):
''' Export boilerplate to ttl file and return the file path'''
#print(out_list) #A list with the values and the file that is the instance
file_name = project.replace('/', '')
if (os.path.exists("../../Ontologies/"+file_name+"/") == False):
os.mkdir("../../Ontologies/"+file_name)
save_path = "../../Ontologies/"+file_name+"/"
completeName = os.path.join(save_path, file_name)
per_instances = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO-instances#")
rdo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO#")
rbo = URIRef("http://delab.csd.auth.gr/ontologies/2018/RBO#")
......@@ -61,7 +77,8 @@ def exportboiltottl(project, prefix, boilerplate, main, suffix):
break
g.add((per_instances+(title+"_"+ main[i][0]['main_choices']), rbo+"isRelatedToSubject", URIRef(str(instance_file))+"#"+ str(spliter_1[len(spliter_1) -1])))
if main[i][0]['verb'] != "":
g.add((per_instances+(title+"_"+ main[i][0]['main_choices']), rbo+"isRelatedToAction", lo + main[i][0]['verb']))
mainverb = main[i][0]['verb'].split(':')
g.add((per_instances+(title+"_"+ main[i][0]['main_choices']), rbo+"isRelatedToAction", lo + mainverb[1].strip()))
if main[i][0]['flow_function_interface_item_system_state_stateset'] != "":
for j in range(0,(len(out_list)-1),2):
if out_list[j]==main[i][0]['flow_function_interface_item_system_state_stateset']:
......@@ -76,10 +93,40 @@ def exportboiltottl(project, prefix, boilerplate, main, suffix):
#if (boilerplate[i][0]['has_prefix'] == True):
# g.add((per_instances+(title+"_"+ main[i][0]['main_choices']), RDF.type, rbo + main[i][0]['main_choices']))
g.serialize(destination='../../Ontologies/'+project+'.ttl', format='turtle')
g.serialize(destination=save_path+file_name+'.ttl', format='turtle')
return (save_path+file_name)
#print(g.serialize(format="turtle").decode("utf-8"))
def shacl(ontotlogy_file):
metrics_dict = {}
metrics_dict["IncompleteRequirement"] = []
metrics_dict["AmbiguousRequirement"] = []
file1 = ontotlogy_file + ".ttl"
target = ontotlogy_file+"infer.ttl"
open(target, 'w').close()
shutil.copyfile(file1, target)
for i in range(3):
print(i+1, 'Cycle of inferencing')
result = subprocess.check_output(["./reqman/apps/reqtool/rest_api/services/shacl-1.3.2/bin/shaclinfer.sh", "-datafile", target])
file_object = open(target, 'a')
res = str(result,'utf-8')
file_object.write(res.strip())
file_object.close()
#need to fiil with all the metrics
g = Graph()
g.load(target, format="turtle")
p = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO#IncompleteRequirement")
for s, p, o in g.triples((None, RDF.type, p)):
#metrics_dict["IncompleteRequirement"] = [s]
get_title = str(s).split("#")
metrics_dict["IncompleteRequirement"].append(get_title[1])
p = URIRef("http://delab.csd.auth.gr/ontologies/2018/RDO#AmbiguousRequirement")
for s, p, o in g.triples((None, RDF.type, p)):
#metrics_dict["IncompleteRequirement"] = [s]
get_title = str(s).split("#")
metrics_dict["AmbiguousRequirement"].append(get_title[1])
return(metrics_dict)
def findclassofmain(listofmain):
classlist = []
......
# TopBraid SHACL API
**An open source implementation of the W3C Shapes Constraint Language (SHACL) based on Apache Jena.**
Contact: Holger Knublauch (holger@topquadrant.com)
Can be used to perform SHACL constraint checking and rule inferencing in any Jena-based Java application.
This API also serves as a reference implementation of the SHACL spec.
Coverage:
* [SHACL Core and SHACL-SPARQL validation](https://www.w3.org/TR/shacl/)
* [SHACL Advanced Features (Rules etc)](https://www.w3.org/TR/shacl-af/)
* [SHACL JavaScript Extensions](https://www.w3.org/TR/shacl-js/)
* [SHACL Compact Syntax](https://w3c.github.io/shacl/shacl-compact-syntax/)
See [SHACL-JS](https://github.com/TopQuadrant/shacl-js) for a pure JavaScript implementation.
The same code is used in the TopBraid products (currently aligned with the TopBraid 6.3 release).
Feedback and questions should become GitHub issues or sent to TopBraid Users mailing list:
https://groups.google.com/forum/#!forum/topbraid-users
Please prefix your messages with [SHACL API]
To get started, look at the class ValidationUtil in
the package org.topbraid.shacl.validation.
There is also an [Example Test Case](../master/src/test/java/org/topbraid/shacl/ValidationExample.java)
## Application dependency
Releases are available in the central maven repository:
```
<dependency>
<groupId>org.topbraid</groupId>
<artifactId>shacl</artifactId>
<version>*VER*</version>
</dependency>
```
## Command Line Usage
Download the latest release from:
`https://repo1.maven.org/maven2/org/topbraid/shacl/`
The binary distribution is:
`https://repo1.maven.org/maven2/org/topbraid/shacl/*VER*/shacl-*VER*-bin.zip`.
Two command line utilities are included: validate (performs constraint validation) and infer (performs SHACL rule inferencing).
To use them, set up your environment similar to https://jena.apache.org/documentation/tools/ (note that the SHACL download includes Jena).
For example, on Windows:
```
SET SHACLROOT=C:\Users\Holger\Desktop\shacl-1.0.0-bin
SET PATH=%PATH%;%SHACLROOT%\bin
```
As another example, for Linux, add to .bashrc these lines:
```
# for shacl
export SHACLROOT=/home/holger/shacl/shacl-1.0.0-bin/shacl-1.0.0/bin
export PATH=$SHACLROOT:$PATH
```
Both tools take the following parameters, for example:
`shaclvalidate.bat -datafile myfile.ttl -shapesfile myshapes.ttl`
where `-shapesfile` is optional and falls back to using the data graph as shapes graph.
Currently only Turtle (.ttl) files and SHACL Compact Syntax (.shaclc) files are supported.
The tools print the validation report or the inferences graph to the output screen.
log4j.rootLogger=INFO, stdlog
log4j.appender.stdlog=org.apache.log4j.ConsoleAppender
log4j.appender.stdlog.target=System.err
log4j.appender.stdlog.layout=org.apache.log4j.PatternLayout
log4j.appender.stdlog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %-20c{1} :: %m%n
## Everything else in Jena
log4j.logger.org.apache.jena=INFO
## Execution logging
log4j.logger.org.apache.jena.arq.info=INFO
log4j.logger.org.apache.jena.arq.exec=INFO
......@@ -255,10 +255,10 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView):
prefixdata.append(self.getprefixdata(id.boilerplate_data_id.id))
maindata.append(self.getmaindata(id.boilerplate_data_id.id))
suffixdata.append(self.getsuffixdata(id.boilerplate_data_id.id))
inference.inferencing(project_title, boildata, prefixdata, maindata, suffixdata)
metrics = inference.inferencing(project_title, boildata, prefixdata, maindata, suffixdata)
#print(prefix[0].boilerplate_data_id.id)
#inference.inferencing(prefix)
instance.update(inference_data = "aaaoooaaa" )
instance.update(inference_data = metrics)
#sprefix = self.simple_prefix(instance["prefix"])
serializer.save()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment