Commit 15d4ab67 authored by Andrei Popescu's avatar Andrei Popescu
Browse files

initialisation of Shacl shapes

- adapted  SchaclTools to new architecture
parent e1802f86
Pipeline #57293 passed with stage
in 26 seconds
......@@ -4,8 +4,3 @@ node_modules
steps.txt
shacl.ttl
turtleTranslation.ttl
.json-schema-spec.txt
.paths.txt
.schemaToTS.ts
schema-traverse.ts
constraints.txt
\ No newline at end of file
"use strict";
exports.__esModule = true;
var rdfTools_1 = require("./rdfTools");
var shaclTools_1 = require("./shaclTools");
var traverse_1 = require("./traverse");
var N3 = require('n3');
var DataFactory = N3.DataFactory;
......@@ -19,8 +20,9 @@ for (var _i = 0, _a = Array.from(schema_object); _i < _a.length; _i++) {
traverse_1.Traverse.initialise(writer, prefix);
rdfTools_1.RDFTools.initialise(object, config.terms); //initialising the filename written by RDF tools with the name of the main object
// filename ,
//ShaclTools.initialise(JsonProcessor.getMainObject(), JsonProcessor.mainObject );
shaclTools_1.ShaclTools.initialise(object, object);
traverse_1.Traverse.traverse('schema', schema);
rdfTools_1.RDFTools.writeTurtle(traverse_1.Traverse.getWriter());
shaclTools_1.ShaclTools.writeShacl();
//ShaclTools.writeShacl(JsonProcessor.getMainObject(), JsonProcessor.getShaclFileText());
}
......@@ -21,9 +21,11 @@ for (let [schemaPath,object] of Array.from(schema_object)){
Traverse.initialise(writer, prefix);
RDFTools.initialise(object, config.terms); //initialising the filename written by RDF tools with the name of the main object
// filename ,
//ShaclTools.initialise(JsonProcessor.getMainObject(), JsonProcessor.mainObject );
ShaclTools.initialise(object, object );
Traverse.traverse('schema', schema);
RDFTools.writeTurtle(Traverse.getWriter());
ShaclTools.writeShacl();
//ShaclTools.writeShacl(JsonProcessor.getMainObject(), JsonProcessor.getShaclFileText());
}
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/alert>;
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/bike>;
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/calendar>;
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/pricingPlan>;
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/region>;
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/rentalHour>;
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/station>;
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/vehicleType>;
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/version>;
......@@ -7,16 +7,48 @@ var ShaclTools = /** @class */ (function () {
}
ShaclTools.initialise = function (filename, mainObj) {
this.fileName = filename;
this.shaclFileText = ""; // reset in case there are more schemas
console.log("mainObject", mainObj);
this.targetClass = ShaclTools.getShaclTarget(mainObj);
this.shaclRoot = this.config.shaclRoot;
console.log("targetClass", this.targetClass);
// Create a ShaclShape object and insert the first entries
this.shaclFileText = this.shaclFileText + ShaclTools.shapeShaclRoot(this.shaclRoot);
this.shaclFileText = this.shaclFileText + 'sh:targetClass ' + this.targetClass + '; \n';
};
ShaclTools.writeShacl = function (filename, shaclFileText) {
ShaclTools.writeShacl = function () {
// Write the Shacl shape on file
this.fs.writeFileSync("build/" + filename + "shacl.ttl", shaclFileText, function (err) {
var filePath = ("build/" + this.fileName + "shacl.ttl").replace(/:/g, '');
this.fs.writeFileSync(filePath, this.shaclFileText, function (err) {
if (err) {
return console.log("error");
}
});
};
ShaclTools.addRequiredTerms = function (termList) {
this.requiredProperties.concat(termList);
};
ShaclTools.isRequired = function (term) {
if (this.requiredProperties.includes(term) != false) {
return term;
}
else {
return false;
}
};
// Methodscompile(mySchema, 'MySchema')
ShaclTools.getShaclTarget = function (mainObject) {
for (var _i = 0, _a = Object.entries(this.config.shaclTargets); _i < _a.length; _i++) {
var entry = _a[_i];
//for(let entry of Array.from(this.config.shaclTargets.entries())){
console.log("entry", entry);
var key = entry[0];
var value = entry[1];
if (key == mainObject) {
return this.config.shaclTargets[key];
}
}
};
ShaclTools.getShaclTypedProperty = function (nome, type) {
var prop = 'sh:property [ \n sh:path <' + nome + '>; \n sh:maxCount 1; \n sh:datatype ' + type + '; \n ];';
return prop;
......@@ -42,6 +74,7 @@ var ShaclTools = /** @class */ (function () {
ShaclTools.config = require('./configs/config-gbfs.json');
ShaclTools.shaclFileText = '';
ShaclTools.fs = require('fs');
ShaclTools.requiredProperties = [];
return ShaclTools;
}());
exports.ShaclTools = ShaclTools;
......@@ -9,24 +9,64 @@ export class ShaclTools {
static config = require('./configs/config-gbfs.json');
//static config = require('./configs/config-battery.json');
static shaclRoot: any;
static targetClass: any;
static shaclFileText = '';
static fs = require('fs');
static fileName: any;
static requiredProperties: Map<string, string>;
static requiredProperties = [];
static initialise(filename, mainObj: string){
this.fileName = filename;
this.shaclFileText = ""; // reset in case there are more schemas
console.log("mainObject", mainObj);
this.targetClass = ShaclTools.getShaclTarget(mainObj);
this.shaclRoot = this.config.shaclRoot;
console.log("targetClass", this.targetClass);
// Create a ShaclShape object and insert the first entries
this.shaclFileText = this.shaclFileText+ShaclTools.shapeShaclRoot(this.shaclRoot);
this.shaclFileText = this.shaclFileText+'sh:targetClass ' + this.targetClass+ '; \n';
}
static writeShacl (filename, shaclFileText){
static writeShacl (){
// Write the Shacl shape on file
this.fs.writeFileSync(`build/${filename}shacl.ttl`, shaclFileText , function(err:any){
let filePath = `build/${this.fileName}shacl.ttl`.replace(/:/g,'');
this.fs.writeFileSync(filePath, this.shaclFileText , function(err:any){
if(err){
return console.log("error");
}
});
}
static addRequiredTerms (termList){
this.requiredProperties.concat(termList);
}
static isRequired(term: string){
if (this.requiredProperties.includes(term)!= false) {
return term;
}
else{
return false;
}
}
// Methodscompile(mySchema, 'MySchema')
static getShaclTarget (mainObject:string) {
for( let entry of Object.entries(this.config.shaclTargets)){
//for(let entry of Array.from(this.config.shaclTargets.entries())){
console.log("entry", entry);
const key = entry[0];
const value = entry[1];
if( key == mainObject){
return this.config.shaclTargets[key];
}
}
}
static getShaclTypedProperty (nome: string, type: string) {
const prop = 'sh:property [ \n sh:path <'+nome+ '>; \n sh:maxCount 1; \n sh:datatype '+ type+'; \n ];';
return prop;
......
"use strict";
exports.__esModule = true;
exports.Traverse = void 0;
var shaclTools_1 = require("./shaclTools");
var RDFTools = require("./rdfTools").RDFTools;
var N3 = require('n3');
var DataFactory = N3.DataFactory;
......@@ -93,6 +94,14 @@ var Traverse = /** @class */ (function () {
}
// if(schema.patternProperties != undefined // No support yet){
//}
// Objects can have required properties defined: these will becom Shacl constraints
// required:[]
// if
var required = schema.required;
console.log("Required", required);
shaclTools_1.ShaclTools.addRequiredTerms(required);
if (shaclTools_1.ShaclTools.isRequired(parentKey)) {
}
// Don't return here: there might be further things defined in an objcet!?
}
if (schema.oneOf != undefined) {
......
......@@ -101,6 +101,21 @@ static traverse (parentKey, schema){
}
// if(schema.patternProperties != undefined // No support yet){
//}
// Objects can have required properties defined: these will becom Shacl constraints
// required:[]
// if
let required = schema.required;
console.log("Required", required);
ShaclTools.addRequiredTerms(required);
if(ShaclTools.isRequired(parentKey)){
}
// Don't return here: there might be further things defined in an objcet!?
}
if(schema.oneOf != undefined){
......
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