Commit 024357d0 authored by Andrei Popescu's avatar Andrei Popescu
Browse files

small updates

- towards integrating the use of termMap
- towards writing shacl shape based on the constraint defined by the json schema
parent 86413142
Pipeline #57062 passed with stage
in 44 seconds
......@@ -15,7 +15,8 @@ for (var _i = 0, _a = Array.from(schema_object); _i < _a.length; _i++) {
var _b = _a[_i], schemaPath = _b[0], object = _b[1];
var schema = require(schemaPath.toString());
var writer = new N3.Writer({ prefixes: config.prefixes });
traverse_1.Traverse.initialise(writer);
var prefix = config.prefix;
traverse_1.Traverse.initialise(writer, prefix);
rdfTools_1.RDFTools.initialise(object); //initialising the filename written by RDF tools with the name of the main object
// filename ,
//ShaclTools.initialise(JsonProcessor.getMainObject(), JsonProcessor.mainObject );
......
......@@ -17,7 +17,8 @@ for( let object in config.sources){
for (let [schemaPath,object] of Array.from(schema_object)){
let schema = require(schemaPath.toString());
let writer = new N3.Writer({prefixes:config.prefixes});
Traverse.initialise(writer);
let prefix = config.prefix;
Traverse.initialise(writer, prefix);
RDFTools.initialise(object); //initialising the filename written by RDF tools with the name of the main object
// filename ,
//ShaclTools.initialise(JsonProcessor.getMainObject(), JsonProcessor.mainObject );
......
{
"prefix": "gbfs",
"jsonObjects": {
"gbfs:Station": "stations",
"gbfs:Bike": "bikes",
"gbfs:Alert": "alerts",
"gbfs:Region": "regions",
"gbfs:VehicleType": "vehicle_types",
"gbfs:PricingPlan": "plans",
"gbfs:Version": "versions",
"gbfs:Calendar": "calendars",
"gbfs:RentalHour": "rental_hours",
"gbfs:Feed": "feeds",
"gbfs:Per_km_pricing":"per_km_pricing",
"gbfs:Per_min_pricing": "per_min_pricing",
"gbfs:Times": "times",
"gbfs:Station_ids": "station_ids",
"gbfs:Region_ids": "region_ids",
"gbfs:User_types": "user_types",
"gbfs:Days": "days",
"gbfs:Rental_methods": "rental_methods",
"gbfs:Station_area": "station_area",
"gbfs:Rental_uris": "rental_uris",
"gbfs:Return_type": "return_type",
"gbfs:Vehicle_assets": "vehicle_assets",
"gbfs:Pricing_plan_ids": "pricing_plan_ids"
},
"shaclTargets": {
"gbfs:Station": "<https://w3id.org/gbfs/terms/station>",
"gbfs:Bike": "<https://w3id.org/gbfs/terms/bike>",
......
......@@ -8,7 +8,8 @@
},
"shaclTargets": {
"sdm:ElectricalMeasurment": "<https://w3id.org/sdm/terms/>"
"sdm:ElectricalMeasurment": "<https://w3id.org/sdm/terms/>",
"sdm:Battery": "<https://w3id.org/sdm/terms/>"
},
"shaclRoot": "<https://w3id.org/sdm/terms/>",
......
......@@ -5,20 +5,12 @@ var RDFTools = require("./rdfTools").RDFTools;
var N3 = require('n3');
var DataFactory = N3.DataFactory;
var namedNode = DataFactory.namedNode, literal = DataFactory.literal, defaultGraph = DataFactory.defaultGraph, quad = DataFactory.quad;
//let config = require('./configs/config-gbfs.json');
var prefix = "gbfs";
//let schema = require('./GBFS/system_pricing_plan.json');
//let schema = require('./GBFS/station_information.json');
//let schema = require('./GBFS/system_hours.json');
//let schema = require('./SmartDataModels/battery.json');
//let schema = require('./SmartDataModels/dataModel.json');
//let schema = require('./GBFS/minecraft.json');
//let schema = require('./GBFS/gbfs.json');
var Traverse = /** @class */ (function () {
function Traverse() {
}
Traverse.initialise = function (writer) {
Traverse.initialise = function (writer, prefix) {
this.writer = writer;
this.prefix = prefix;
};
Traverse.traverse = function (parentKey, schema) {
if (!schema) {
......@@ -27,39 +19,39 @@ var Traverse = /** @class */ (function () {
if (schema.type != undefined) { // If the schema/sub-schema has a type
console.log("key: ", parentKey);
if (schema.type === 'string') { // Base Case
this.writer.addQuad(RDFTools.node_node_node(prefix + ':' + parentKey, 'rdf:type', 'xsd:string'));
this.writer.addQuad(RDFTools.node_node_literal(prefix + ':' + parentKey, 'rdfs:label', schema.description));
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));
if (schema["enum"] != undefined) { // schema.enum can also be found in a string schema
this.writer.addQuad(RDFTools.getOneOfQuad(prefix, RDFTools.capitalizeFirstLetter(parentKey), schema["enum"], this.writer));
this.writer.addQuad(RDFTools.getOneOfQuad(this.prefix, RDFTools.capitalizeFirstLetter(parentKey), schema["enum"], this.writer));
return;
}
return parentKey;
}
if (schema.type === 'number') { // Base Case
this.writer.addQuad(RDFTools.node_node_node(prefix + ':' + parentKey, 'rdf:type', 'xsd:integer'));
this.writer.addQuad(RDFTools.node_node_literal(prefix + ':' + parentKey, 'rdfs:label', schema.description));
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));
return parentKey;
}
if (schema.type === 'integer') { // Base Case
this.writer.addQuad(RDFTools.node_node_node(prefix + ':' + parentKey, 'rdf:type', 'xsd:integer'));
this.writer.addQuad(RDFTools.node_node_literal(prefix + ':' + parentKey, 'rdfs:label', schema.description));
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));
return parentKey;
}
if (schema.type === 'boolean') { // Base Case
this.writer.addQuad(RDFTools.node_node_node(prefix + ':' + parentKey, 'rdf:type', 'xsd:boolean'));
this.writer.addQuad(RDFTools.node_node_literal(prefix + ':' + parentKey, 'rdfs:label', schema.description));
this.writer.addQuad(RDFTools.node_node_node(this.prefix + ':' + parentKey, 'rdf:type', 'xsd:boolean'));
this.writer.addQuad(RDFTools.node_node_literal(this.prefix + ':' + parentKey, 'rdfs:label', schema.description));
return parentKey;
}
if (schema["enum"] != undefined) { // Base Case: schema.enum
this.writer.addQuad(RDFTools.getOneOfQuad(prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.items["enum"], this.writer));
this.writer.addQuad(RDFTools.node_node_literal(prefix + ':' + parentKey, 'rdfs:label', schema.description));
this.writer.addQuad(RDFTools.getOneOfQuad(this.prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.items["enum"], this.writer));
this.writer.addQuad(RDFTools.node_node_literal(this.prefix + ':' + parentKey, 'rdfs:label', schema.description));
return parentKey;
}
if (schema.type === 'array') {
console.log("array: ");
console.log("array schema", schema);
this.writer.addQuad(RDFTools.node_node_node(prefix + ':' + parentKey, 'rdfs:range', prefix + ":" + RDFTools.capitalizeFirstLetter(parentKey)));
this.writer.addQuad(RDFTools.node_node_node(prefix + ':' + RDFTools.capitalizeFirstLetter(parentKey), 'rdf:type', 'rdfs:Class'));
this.writer.addQuad(RDFTools.node_node_node(this.prefix + ':' + parentKey, 'rdfs:range', this.prefix + ":" + RDFTools.capitalizeFirstLetter(parentKey)));
this.writer.addQuad(RDFTools.node_node_node(this.prefix + ':' + RDFTools.capitalizeFirstLetter(parentKey), 'rdf:type', 'rdfs:Class'));
if (schema.items != undefined) {
//
if (schema.items.type === 'object') {
......@@ -72,10 +64,10 @@ var Traverse = /** @class */ (function () {
}
}
if (schema.items["enum"] != undefined) { // schema.items.enum
this.writer.addQuad(RDFTools.getOneOfQuad(prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.items["enum"], this.writer));
this.writer.addQuad(RDFTools.getOneOfQuad(this.prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.items["enum"], this.writer));
}
if (schema.items['$ref'] != undefined) { // No support for $ref
this.writer.addQuad(RDFTools.node_node_node(prefix + ':' + parentKey, 'rdfs:hasProperty', schema.items['$ref']));
this.writer.addQuad(RDFTools.node_node_node(this.prefix + ':' + parentKey, 'rdfs:hasProperty', schema.items['$ref']));
}
}
// key oneof <-,-,-,-,->
......@@ -95,8 +87,8 @@ var Traverse = /** @class */ (function () {
}
console.log("propertyLIst", propertyList);
// key hasProperties propertyList
this.writer.addQuad(RDFTools.node_node_node(prefix + ':' + parentKey, 'rdfs:range', prefix + ":" + RDFTools.capitalizeFirstLetter(parentKey)));
this.writer.addQuad(RDFTools.node_node_list(prefix + ':' + RDFTools.capitalizeFirstLetter(parentKey), 'rdfs:hasProperty', this.writer.list(propertyList)));
this.writer.addQuad(RDFTools.node_node_node(this.prefix + ':' + parentKey, 'rdfs:range', this.prefix + ":" + RDFTools.capitalizeFirstLetter(parentKey)));
this.writer.addQuad(RDFTools.node_node_list(this.prefix + ':' + RDFTools.capitalizeFirstLetter(parentKey), 'rdfs:hasProperty', this.writer.list(propertyList)));
propertyList = [];
}
// if(schema.patternProperties != undefined // No support yet){
......
......@@ -8,24 +8,14 @@ const N3 = require('n3');
const { DataFactory } = N3;
const { namedNode, literal, defaultGraph, quad } = DataFactory;
//let config = require('./configs/config-gbfs.json');
let prefix ="gbfs";
//let schema = require('./GBFS/system_pricing_plan.json');
//let schema = require('./GBFS/station_information.json');
//let schema = require('./GBFS/system_hours.json');
//let schema = require('./SmartDataModels/battery.json');
//let schema = require('./SmartDataModels/dataModel.json');
//let schema = require('./GBFS/minecraft.json');
//let schema = require('./GBFS/gbfs.json');
export class Traverse{
static writer:any;
static prefix:any;
static initialise (writer){
static initialise (writer, prefix){
this.writer = writer;
this.prefix = prefix;
}
static traverse (parentKey, schema){
......@@ -35,46 +25,43 @@ static traverse (parentKey, schema){
if (schema.type != undefined){ // If the schema/sub-schema has a type
console.log("key: ", parentKey);
if (schema.type === 'string') { // Base Case
this.writer.addQuad(RDFTools.node_node_node(prefix+':'+parentKey, 'rdf:type', 'xsd:string'));
this.writer.addQuad(RDFTools.node_node_literal(prefix+':'+parentKey, 'rdfs:label', schema.description));
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));
if (schema.enum != undefined){ // schema.enum can also be found in a string schema
this.writer.addQuad(RDFTools.getOneOfQuad(prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.enum, this.writer));
this.writer.addQuad(RDFTools.getOneOfQuad(this.prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.enum, this.writer));
return;
}
return parentKey;
}
if (schema.type === 'number') { // Base Case
this.writer.addQuad(RDFTools.node_node_node(prefix+':'+parentKey, 'rdf:type', 'xsd:integer'));
this.writer.addQuad(RDFTools.node_node_literal(prefix+':'+parentKey, 'rdfs:label', schema.description));
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));
return parentKey;
}
if (schema.type === 'integer') {// Base Case
this.writer.addQuad(RDFTools.node_node_node(prefix+':'+parentKey, 'rdf:type', 'xsd:integer'));
this.writer.addQuad(RDFTools.node_node_literal(prefix+':'+parentKey, 'rdfs:label', schema.description));
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));
return parentKey;
}
if (schema.type === 'boolean') {// Base Case
this.writer.addQuad(RDFTools.node_node_node(prefix+':'+parentKey, 'rdf:type', 'xsd:boolean'));
this.writer.addQuad(RDFTools.node_node_literal(prefix+':'+parentKey, 'rdfs:label', schema.description));
this.writer.addQuad(RDFTools.node_node_node(this.prefix+':'+parentKey, 'rdf:type', 'xsd:boolean'));
this.writer.addQuad(RDFTools.node_node_literal(this.prefix+':'+parentKey, 'rdfs:label', schema.description));
return parentKey;
}
if (schema.enum != undefined){ // Base Case: schema.enum
this.writer.addQuad(RDFTools.getOneOfQuad(prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.items.enum, this.writer));
this.writer.addQuad(RDFTools.node_node_literal(prefix+':'+parentKey, 'rdfs:label', schema.description));
this.writer.addQuad(RDFTools.getOneOfQuad(this.prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.items.enum, this.writer));
this.writer.addQuad(RDFTools.node_node_literal(this.prefix+':'+parentKey, 'rdfs:label', schema.description));
return parentKey;
}
if (schema.type === 'array'){
console.log("array: ");
console.log("array schema", schema);
this.writer.addQuad(RDFTools.node_node_node(prefix+':'+parentKey, 'rdfs:range', prefix+":"+RDFTools.capitalizeFirstLetter(parentKey) ));
this.writer.addQuad(RDFTools.node_node_node(prefix+':'+RDFTools.capitalizeFirstLetter(parentKey), 'rdf:type', 'rdfs:Class' ));
this.writer.addQuad(RDFTools.node_node_node(this.prefix+':'+parentKey, 'rdfs:range', this.prefix+":"+RDFTools.capitalizeFirstLetter(parentKey) ));
this.writer.addQuad(RDFTools.node_node_node(this.prefix+':'+RDFTools.capitalizeFirstLetter(parentKey), 'rdf:type', 'rdfs:Class' ));
if (schema.items != undefined){
//
if (schema.items.type === 'object'){
if (schema.items != undefined){ // usually an array has items
if (schema.items.type === 'object'){ // but it can happen that it has a nested object
this.traverse(parentKey, schema.items);
//console.log("schema items", schema.items);
for(let item of Object.keys(schema.items)){
......@@ -83,10 +70,10 @@ static traverse (parentKey, schema){
}
}
if(schema.items.enum != undefined){// schema.items.enum
this.writer.addQuad(RDFTools.getOneOfQuad(prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.items.enum, this.writer));
this.writer.addQuad(RDFTools.getOneOfQuad(this.prefix, RDFTools.capitalizeFirstLetter(parentKey), schema.items.enum, this.writer));
}
if(schema.items['$ref'] != undefined){// No support for $ref
this.writer.addQuad(RDFTools.node_node_node(prefix+':'+parentKey, 'rdfs:hasProperty',schema.items['$ref'] ));
this.writer.addQuad(RDFTools.node_node_node(this.prefix+':'+parentKey, 'rdfs:hasProperty',schema.items['$ref'] ));
}
}
// key oneof <-,-,-,-,->
......@@ -106,9 +93,9 @@ static traverse (parentKey, schema){
}
console.log("propertyLIst", propertyList);
// key hasProperties propertyList
this.writer.addQuad(RDFTools.node_node_node(prefix+':'+parentKey, 'rdfs:range', prefix+":"+RDFTools.capitalizeFirstLetter(parentKey) ));
this.writer.addQuad(RDFTools.node_node_node(this.prefix+':'+parentKey, 'rdfs:range', this.prefix+":"+RDFTools.capitalizeFirstLetter(parentKey) ));
this.writer.addQuad(RDFTools.node_node_list(prefix+':'+RDFTools.capitalizeFirstLetter(parentKey), 'rdfs:hasProperty', this.writer.list(propertyList)));
this.writer.addQuad(RDFTools.node_node_list(this.prefix+':'+RDFTools.capitalizeFirstLetter(parentKey), 'rdfs:hasProperty', this.writer.list(propertyList)));
propertyList = [];
}
// if(schema.patternProperties != undefined // No support yet){
......
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