Commit de6215b9 authored by Andrei Popescu's avatar Andrei Popescu
Browse files

shacl shapes available as well

- they only include required properties for now
parent 15d4ab67
Pipeline #57338 passed with stage
in 24 seconds
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/alert>;
sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <ttl>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <data>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <alerts>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <alert_id>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <type>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <summary>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];
\ No newline at end of file
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/bike>;
sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <ttl>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <data>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <bikes>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <bike_id>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <lat>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <lon>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];
\ No newline at end of file
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/calendar>;
sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <ttl>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <version>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <data>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <calendars>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <start_month>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <start_day>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <end_month>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <end_day>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];
\ No newline at end of file
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/pricingPlan>;
sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <ttl>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <version>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <data>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <plans>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <plan_id>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <url>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <name>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <currency>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <price>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <description>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <start>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <rate>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <interval>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <start>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <rate>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <interval>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];
\ No newline at end of file
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/region>;
sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <ttl>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <version>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <data>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <regions>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <region_id>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <name>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];
\ No newline at end of file
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/rentalHour>;
sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <ttl>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <version>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <data>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <rental_hours>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <start_time>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <end_time>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];
\ No newline at end of file
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/station>;
sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <ttl>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <version>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <data>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <stations>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <station_id>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <name>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <lat>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <lon>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <type>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];
\ No newline at end of file
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/vehicleType>;
sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <ttl>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <version>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <data>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <vehicle_types>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <vehicle_type_id>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <form_factor>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <propulsion_type>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <name>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <icon_url>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <icon_last_modified>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];
\ No newline at end of file
<https://w3id.org/gbfs/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/gbfs/terms/version>;
sh:property [
sh:path <last_updated>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <ttl>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype integer;
];sh:property [
sh:path <version>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <data>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <versions>;
sh:minCount 1;
sh:maxCount 1;
];sh:property [
sh:path <version>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];sh:property [
sh:path <url>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype string;
];
\ No newline at end of file
......@@ -8,10 +8,8 @@ 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';
......@@ -25,8 +23,11 @@ var ShaclTools = /** @class */ (function () {
}
});
};
ShaclTools.getRequiredProperties = function () {
return this.requiredProperties;
};
ShaclTools.addRequiredTerms = function (termList) {
this.requiredProperties.concat(termList);
this.requiredProperties = this.requiredProperties + termList;
};
ShaclTools.isRequired = function (term) {
if (this.requiredProperties.includes(term) != false) {
......@@ -49,6 +50,9 @@ var ShaclTools = /** @class */ (function () {
}
}
};
ShaclTools.addToShape = function (prop) {
this.shaclFileText = this.shaclFileText + prop;
};
ShaclTools.getShaclTypedProperty = function (nome, type) {
var prop = 'sh:property [ \n sh:path <' + nome + '>; \n sh:maxCount 1; \n sh:datatype ' + type + '; \n ];';
return prop;
......
......@@ -19,16 +19,13 @@ export class ShaclTools {
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 (){
// Write the Shacl shape on file
let filePath = `build/${this.fileName}shacl.ttl`.replace(/:/g,'');
......@@ -39,8 +36,11 @@ export class ShaclTools {
});
}
static getRequiredProperties(){
return this.requiredProperties;
}
static addRequiredTerms (termList){
this.requiredProperties.concat(termList);
this.requiredProperties = this.requiredProperties + termList;
}
static isRequired(term: string){
......@@ -53,9 +53,7 @@ export class ShaclTools {
}
// 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);
......@@ -67,6 +65,10 @@ export class ShaclTools {
}
}
static addToShape(prop){
this.shaclFileText = this.shaclFileText+prop;
}
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;
......
......@@ -22,6 +22,12 @@ var Traverse = /** @class */ (function () {
if (schema.type === 'string') { // Base Case
this.writer.addQuad(RDFTools.node_node_node(this.prefix + ':' + parentKey, 'rdf:type', 'xsd:string'));
this.writer.addQuad(RDFTools.node_node_literal(this.prefix + ':' + parentKey, 'rdfs:label', schema.description));
console.log("parentKey", parentKey);
console.log("required in if", shaclTools_1.ShaclTools.getRequiredProperties());
if (shaclTools_1.ShaclTools.isRequired(parentKey)) {
console.log("this property is required");
shaclTools_1.ShaclTools.addToShape(shaclTools_1.ShaclTools.getShaclTypedRequiredProperty(parentKey, 'string'));
}
if (schema["enum"] != undefined) { // schema.enum can also be found in a string schema
this.writer.addQuad(RDFTools.getOneOfQuad(this.prefix, RDFTools.capitalizeFirstLetter(parentKey), schema["enum"], this.writer));
return;
......@@ -33,6 +39,9 @@ var Traverse = /** @class */ (function () {
this.writer.addQuad(RDFTools.node_node_node(this.prefix + ':' + parentKey, 'rdf:type', 'xsd:integer'));
this.writer.addQuad(RDFTools.node_node_literal(this.prefix + ':' + parentKey, 'rdfs:label', schema.description));
}
if (shaclTools_1.ShaclTools.isRequired(parentKey)) {
shaclTools_1.ShaclTools.addToShape(shaclTools_1.ShaclTools.getShaclTypedRequiredProperty(parentKey, 'integer'));
}
return parentKey;
}
if (schema.type === 'integer') { // Base Case
......@@ -40,6 +49,9 @@ var Traverse = /** @class */ (function () {
this.writer.addQuad(RDFTools.node_node_node(this.prefix + ':' + parentKey, 'rdf:type', 'xsd:integer'));
this.writer.addQuad(RDFTools.node_node_literal(this.prefix + ':' + parentKey, 'rdfs:label', schema.description));
}
if (shaclTools_1.ShaclTools.isRequired(parentKey)) {
shaclTools_1.ShaclTools.addToShape(shaclTools_1.ShaclTools.getShaclTypedRequiredProperty(parentKey, 'integer'));
}
return parentKey;
}
if (schema.type === 'boolean') { // Base Case
......@@ -79,6 +91,11 @@ var Traverse = /** @class */ (function () {
return;
}
if (schema.type === 'object') {
var required = schema.required;
shaclTools_1.ShaclTools.addRequiredTerms(required);
if (shaclTools_1.ShaclTools.isRequired(parentKey)) {
shaclTools_1.ShaclTools.addToShape(shaclTools_1.ShaclTools.getShaclRequiredProperty(parentKey));
}
var propertyList = [];
propertyList = [];
if (schema.properties != undefined) {
......@@ -97,11 +114,6 @@ var Traverse = /** @class */ (function () {
// 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) {
......
......@@ -27,6 +27,14 @@ static traverse (parentKey, schema){
this.writer.addQuad(RDFTools.node_node_node(this.prefix+':'+parentKey, 'rdf:type', 'xsd:string'));
this.writer.addQuad(RDFTools.node_node_literal(this.prefix+':'+parentKey, 'rdfs:label', schema.description));
console.log("parentKey", parentKey);
console.log("required in if", ShaclTools.getRequiredProperties());
if(ShaclTools.isRequired(parentKey)){
console.log("this property is required");
ShaclTools.addToShape(ShaclTools.getShaclTypedRequiredProperty(parentKey, 'string'));
}
if (schema.enum != undefined){ // schema.enum can also be found in a string schema