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

correcting Shacl shape

parent 1d6f78b6
Pipeline #54963 passed with stage
in 25 seconds
......@@ -25,6 +25,8 @@ sdm:refDevice rdf:type rdf:Property;
sdm:refTargetDevice rdf:type rdf:Property;
rdfs:range sdm:RefTargetDevice;
rdfs:label "Relationship. Device(s) for which the measurement was taken."@en.
sdm:dateEnergyMeteringStarted rdfs:range xsd:string;
rdfs:label "Property. Model:'http://schema.org/DateTime'. The starting date for metering energy."@en.
sdm:totalActiveEnergyImport rdfs:range xsd:integer;
rdfs:label "Property. Model:'https://schema.org/Number'. Units:'kilowatt hour (kWh)'. Total energy imported i.e. consumed since metering started (since `dateEnergyMeteringStarted`)."@en.
sdm:totalReactiveEnergyImport rdfs:range xsd:integer;
......
undefined<https://w3id.org/gbfs/shapes/> a sh:NodeShape;
sh:targetClass undefined;
undefined<https://w3id.org/sdm/terms/> a sh:NodeShape;
sh:targetClass <https://w3id.org/sdm/terms/>;
sh:property [
sh:path <type>;
sh:minCount 1;
sh:maxCount 1;
sh:datatype xsd:string;
];
sh:property [
sh:path <refDevice>;
sh:maxCount 1;
......@@ -8,6 +14,11 @@ sh:property [
sh:path <refTargetDevice>;
sh:maxCount 1;
];
sh:property [
sh:path <dateEnergyMeteringStarted>;
sh:maxCount 1;
sh:datatype xsd:string;
];
sh:property [
sh:path <totalActiveEnergyImport>;
sh:maxCount 1;
......@@ -81,34 +92,154 @@ sh:property [
sh:path <reactiveEnergyImport>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <apparentEnergyImport>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <activeEnergyExport>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <reactiveEnergyExport>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <apparentEnergyExport>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <activePower>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <reactivePower>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <apparentPower>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <totalPowerFactor>;
sh:maxCount 1;
......@@ -118,6 +249,21 @@ sh:property [
sh:path <powerFactor>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <totalDisplacementPowerFactor>;
sh:maxCount 1;
......@@ -127,10 +273,40 @@ sh:property [
sh:path <displacementPowerFactor>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <current>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <N>;
sh:maxCount 1;
......@@ -140,6 +316,21 @@ sh:property [
sh:path <phaseVoltage>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <phaseToPhaseVoltage>;
sh:maxCount 1;
......@@ -163,7 +354,37 @@ sh:property [
sh:path <thdVoltage>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <thdCurrent>;
sh:maxCount 1;
];
sh:property [
sh:path <L1>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L2>;
sh:maxCount 1;
sh:datatype xsd:float;
];
sh:property [
sh:path <L3>;
sh:maxCount 1;
sh:datatype xsd:float;
];
......@@ -11,6 +11,20 @@
"./GBFS/system_hours.json": "gbfs:RentalHour"
},
"shaclTargets": {
"gbfs:Station": "<https://w3id.org/gbfs/terms/station>",
"gbfs:Bike": "<https://w3id.org/gbfs/terms/bike>",
"gbfs:Alert": "<https://w3id.org/gbfs/terms/alert>",
"gbfs:Region": "<https://w3id.org/gbfs/terms/region>",
"gbfs:VehicleType": "<https://w3id.org/gbfs/terms/vehicleType>",
"gbfs:PricingPlan": "<https://w3id.org/gbfs/terms/pricingPlan>",
"gbfs:Version": "<https://w3id.org/gbfs/terms/version>",
"gbfs:Calendar": "<https://w3id.org/gbfs/terms/calendar>",
"gbfs:RentalHour": "<https://w3id.org/gbfs/terms/rentalHour>",
"gbfs:Feed": "<https://w3id.org/gbfs/terms/feed>"
},
"prefixes": {
"gbfs": "https://w3id.org/gbfs/terms",
"schema": "http://schema.org/#",
......
{
"prefix": "sdm",
"jsonObjects": {
"sdm:ElectricalMeasurment": "allOf",
"sdm:RefDevice": "refDevice",
......@@ -29,6 +29,12 @@
"sources": {
"./SmartDataModels/dataModel.json": "sdm:ElectricalMeasurment"
},
"shaclTargets": {
"sdm:ElectricalMeasurment": "<https://w3id.org/sdm/terms/>"
},
"shaclRoot": "<https://w3id.org/sdm/terms/>",
"prefixes": {
"sdm": "https://smart-data-models.github.io/dataModel.Energy/ThreePhaseAcMeasurement/terms",
......
......@@ -3,6 +3,7 @@ exports.__esModule = true;
exports.GbfsPattern = void 0;
var shaclTools_1 = require("./shaclTools");
var rdfTools_1 = require("./rdfTools");
var jsonProcessor_1 = require("./jsonProcessor");
var N3 = require('n3');
var DataFactory = N3.DataFactory;
var namedNode = DataFactory.namedNode, literal = DataFactory.literal, defaultGraph = DataFactory.defaultGraph, quad = DataFactory.quad;
......@@ -42,7 +43,7 @@ var GbfsPattern = /** @class */ (function () {
this.writer.addQuad(rdfTools_1.RDFTools.node_node_literal(this.creator1, 'foaf:mbox', 'mailto:pieter.colpaert@imec.be'));
this.writer.addQuad(rdfTools_1.RDFTools.node_node_literal(this.creator1, 'foaf:name', 'Pieter Colpaert'));
// Create a ShaclShape object and insert the first entries
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclRoot();
//this.shaclFileText = this.shaclFileText+ ShaclTools.getShaclRoot();
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTargetClass() + '\n';
};
/** Creates and writes quads for the main object's properties,
......@@ -218,7 +219,7 @@ var GbfsPattern = /** @class */ (function () {
// The property is available in map, so we do not add it to the vocabulary
}
// Write the property to the Shacl shape
if (shaclTools_1.ShaclTools.isRequired(term)) {
if (jsonProcessor_1.JsonProcessor.isRequired(term)) {
// If the type is primitive
if (termType == 'boolean' || termType == 'string' || termType == 'number') {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedRequiredProperty(term, rdfTools_1.RDFTools.getXsdType(termType)) + '\n';
......
......@@ -6,6 +6,7 @@ import {DataFactory, Literal, Quad, Store} from "n3";
import literal = DataFactory.literal;
import { NamedNode } from "n3/lib/N3DataFactory";
import { off } from "process";
import { JsonProcessor } from "./jsonProcessor";
const N3 = require('n3');
const { DataFactory } = N3;
......@@ -71,7 +72,7 @@ export class GbfsPattern {
this.writer.addQuad(RDFTools.node_node_literal(this.creator1, 'foaf:mbox', 'mailto:pieter.colpaert@imec.be'));
this.writer.addQuad(RDFTools.node_node_literal(this.creator1, 'foaf:name', 'Pieter Colpaert'));
// Create a ShaclShape object and insert the first entries
this.shaclFileText = this.shaclFileText+ ShaclTools.getShaclRoot();
//this.shaclFileText = this.shaclFileText+ ShaclTools.getShaclRoot();
this.shaclFileText = this.shaclFileText+ ShaclTools.getShaclTargetClass()+'\n';
}
......@@ -266,7 +267,7 @@ export class GbfsPattern {
}
// Write the property to the Shacl shape
if (ShaclTools.isRequired(term)){
if (JsonProcessor.isRequired(term)){
// If the type is primitive
if (termType == 'boolean' || termType == 'string' || termType == 'number') {
this.shaclFileText = this.shaclFileText+ShaclTools.getShaclTypedRequiredProperty(term, RDFTools.getXsdType(termType))+'\n';
......
......@@ -10,6 +10,7 @@ var JsonProcessor = /** @class */ (function () {
function JsonProcessor() {
}
JsonProcessor.initialise = function (source, mainObj) {
// RDF Vocabulary ------------------
// Getting configuration elements
for (var object in this.config.jsonObjects) {
this.rdf_json_objects.set(object, this.config.jsonObjects[object]);
......@@ -36,14 +37,25 @@ var JsonProcessor = /** @class */ (function () {
this.creators.push(creator);
this.writer.addQuad(rdfTools_1.RDFTools.node_node_node('https://w3id.org/sdm/terms/', 'dcterms:creator', this.config.creators[creator]));
}
// Shacl shape -------------------
// Setting a map containing < requiredProp, existingTermForRequiredProp>.
this.shaclRoot = this.config.shaclRoot;
for (var _i = 0, _a = this.jsonSchema.required; _i < _a.length; _i++) {
var requiredProp = _a[_i];
this.requiredMap.set(requiredProp.toString(), this.termMap.get(requiredProp.toString()));
if (this.termMap.has(requiredProp) != false) {
this.requiredMap.set(requiredProp.toString(), this.termMap.get(requiredProp.toString()));
}
else {
this.requiredMap.set(requiredProp.toString(), requiredProp.toString());
}
}
for (var object in this.config.shaclTargets) {
this.targets.set(object, this.config.shaclTargets[object]);
}
this.shaclTargetClass = JsonProcessor.getShaclTarget(mainObj);
// Create a ShaclShape object and insert the first entries
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclRoot();
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTargetClass() + '\n';
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.shapeShaclRoot(this.shaclRoot);
this.shaclFileText = this.shaclFileText + 'sh:targetClass ' + this.shaclTargetClass + '; \n';
};
JsonProcessor.callJsonTraverseRecursive = function () {
var depth = 0;
......@@ -93,14 +105,31 @@ var JsonProcessor = /** @class */ (function () {
if (propDescription != undefined) {
this.writer.addQuad(rdfTools_1.RDFTools.node_node_literal(this.prefix + ':' + prop, 'rdfs:label', propDescription.toString()));
}
// Shacl shape text
if (shaclTools_1.ShaclTools.isRequired(prop)) {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedRequiredProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
else {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
// Shacl shape text
if (JsonProcessor.isRequired(prop)) {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedRequiredProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
else {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
return;
}
if (propType == 'string') {
if (this.termMap.has(prop) == false) {
this.termMap.set(prop, 'sdm:' + prop);
this.writer.addQuad(rdfTools_1.RDFTools.node_node_node(this.prefix + ':' + prop, 'rdfs:range', 'xsd:string'));
if (propDescription != undefined) {
this.writer.addQuad(rdfTools_1.RDFTools.node_node_literal(this.prefix + ':' + prop, 'rdfs:label', propDescription.toString()));
}
}
// Shacl shape text
if (JsonProcessor.isRequired(prop)) {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedRequiredProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
else {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
return;
}
if (propType == 'boolean') {
......@@ -110,13 +139,13 @@ var JsonProcessor = /** @class */ (function () {
if (propDescription != undefined) {
this.writer.addQuad(rdfTools_1.RDFTools.node_node_literal(this.prefix + ':' + prop, 'rdfs:label', propDescription.toString()));
}
// Shacl shape text
if (shaclTools_1.ShaclTools.isRequired(prop)) {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedRequiredProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
else {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
}
// Shacl shape text
if (JsonProcessor.isRequired(prop)) {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedRequiredProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
else {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
return;
}
......@@ -147,7 +176,7 @@ var JsonProcessor = /** @class */ (function () {
this.writer.addQuad(subPropQuad);
}
// Shacl shape text
if (shaclTools_1.ShaclTools.isRequired(prop)) {
if (JsonProcessor.isRequired(prop)) {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclRequiredProperty(prop) + '\n';
}
else { // Else the property is not required
......@@ -184,23 +213,40 @@ var JsonProcessor = /** @class */ (function () {
JsonProcessor.getMainObject = function () {
return this.mainObject;
};
JsonProcessor.getRequiredProperties = function () {
return this.requiredMap;
JsonProcessor.getWriter = function () {
return this.writer;
};
// For the Shacl shape
JsonProcessor.getShaclTarget = function (mainObject) {
for (var _i = 0, _a = Array.from(this.targets.entries()); _i < _a.length; _i++) {
var entry = _a[_i];
var key = entry[0];
var value = entry[1];
if (key == mainObject) {
return this.targets.get(key);
}
}
};
JsonProcessor.isRequired = function (prop) {
if (this.requiredMap.has(prop)) {
return true;
}
else {
return false;
}
};
JsonProcessor.getShaclFileText = function () {
return this.shaclFileText;
};
JsonProcessor.getWriter = function () {
return this.writer;
};
// From config.json, we get:
// prefixes, terms, , schema_objects(in the main)
JsonProcessor.config = require('./configs/config-smartdatamodel.json');
JsonProcessor.rdf_json_objects = new Map();
JsonProcessor.termMap = new Map();
JsonProcessor.creators = [];
// Shacl-related
// Shacl shape
JsonProcessor.requiredMap = new Map();
JsonProcessor.targets = new Map();
return JsonProcessor;
}());
exports.JsonProcessor = JsonProcessor;
......@@ -20,11 +20,15 @@ export class JsonProcessor {
static properties: any;
static prefix: any;
static creators: any[] = [];
// Shacl-related
// Shacl shape
static requiredMap = new Map<string, string>();
static shaclFileText:any;
static shaclTargetClass: any;
static targets = new Map<string, string>();
static shaclRoot: any;
static initialise ( source:string, mainObj: string ){
// RDF Vocabulary -------------------------
// Getting configuration elements
for (let object in this.config.jsonObjects){
this.rdf_json_objects.set(object, this.config.jsonObjects[object]);
......@@ -32,7 +36,6 @@ export class JsonProcessor {
for (let object in this.config.terms){
this.termMap.set(object, this.config.terms[object]);
}
this.writer = new N3.Writer({prefixes:this.config.prefixes});
// Setting up basic info
this.jsonSource = source; // Needed when creating a ShaclShape object
......@@ -43,7 +46,6 @@ export class JsonProcessor {
// Set path (TODO: set from confi.json)
this.path = this.jsonSchema[this.mainJsonObject];
this.properties = this.path[2].properties; // Path to the properties of the main object
//
this.writer.addQuad(RDFTools.node_node_node('https://w3id.org/sdm/terms/'+ this.mainJsonObject, 'rdf:type', 'foaf:Document'));
this.writer.addQuad(RDFTools.node_node_literal('https://w3id.org/sdm/terms/'+ this.mainJsonObject, 'rdfs:comment', this.jsonSchema.description));
this.writer.addQuad(RDFTools.