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

small correction traverse parameters

parent 727d3a0e
......@@ -4,28 +4,22 @@ var rdfTools_1 = require("./rdfTools");
var traverse_1 = require("./traverse");
var N3 = require('n3');
var DataFactory = N3.DataFactory;
// Main objects that are passed to the rdfVocabulary.ts.
// there is one per json schema.
var schema_object = new Map();
var config = require('./configs/config-gbfs.json');
//const config = require('./configs/config-smartdatamodel.json');
//const config = require('./configs/config-battery.json');
for (var object in config.sources) {
schema_object.set(object, config.sources[object]);
}
// main Function for recursive jsonProcessor
// For each schema in the system, traverse and RDF it.
for (var _i = 0, _a = Array.from(schema_object); _i < _a.length; _i++) {
var _b = _a[_i], schemaPath = _b[0], object = _b[1];
console.log("schemaPath", schemaPath, "object:", object);
var schema = require(schemaPath.toString());
var writer = new N3.Writer({ prefixes: config.prefixes });
traverse_1.Traverse.initialise(writer);
//JsonProcessor.initialise(schema, object);
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 );
//JsonProcessor.callJsonTraverseRecursive();
traverse_1.Traverse.traverse('schema', schema, []);
traverse_1.Traverse.traverse('schema', schema);
rdfTools_1.RDFTools.writeTurtle(traverse_1.Traverse.getWriter());
//ShaclTools.writeShacl(JsonProcessor.getMainObject(), JsonProcessor.getShaclFileText());
}
......@@ -4,39 +4,25 @@ import { Traverse } from './traverse';
const N3 = require('n3');
const { DataFactory } = N3;
// Main objects that are passed to the rdfVocabulary.ts.
// there is one per json schema.
let schema_object = new Map<string, string>();
const config = require('./configs/config-gbfs.json');
//const config = require('./configs/config-smartdatamodel.json');
//const config = require('./configs/config-battery.json');
for( let object in config.sources){
schema_object.set(object, config.sources[object]);
}
// main Function for recursive jsonProcessor
// For each schema in the system, traverse and RDF it.
for (let [schemaPath,object] of Array.from(schema_object)){
console.log("schemaPath", schemaPath, "object:", object);
let schema = require(schemaPath.toString());
let writer = new N3.Writer({prefixes:config.prefixes});
Traverse.initialise(writer);
//JsonProcessor.initialise(schema, object);
RDFTools.initialise(object); //initialising the filename written by RDF tools with the name of the main object
// filename ,
//ShaclTools.initialise(JsonProcessor.getMainObject(), JsonProcessor.mainObject );
//JsonProcessor.callJsonTraverseRecursive();
Traverse.traverse('schema', schema, []);
Traverse.traverse('schema', schema);
RDFTools.writeTurtle(Traverse.getWriter());
//ShaclTools.writeShacl(JsonProcessor.getMainObject(), JsonProcessor.getShaclFileText());
}
@prefix gbfs: <https://w3id.org/gbfs/terms>.
@prefix schema: <http://schema.org/#>.
@prefix ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix dcterms: <http://purl.org/dc/terms/>.
@prefix vs: <http://www.w3.org/2003/06/sw-vocab-status/ns#>.
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>.
@prefix vann: <http://purl.org/vocab/vann/>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix jsonsc: <https://www.w3.org/2019/wot/json-schema#>.
@prefix airs: <https://raw.githubusercontent.com/airs-linked-data/lov/latest/src/airs_vocabulary.ttl#>.
@prefix vso: <http://purl.org/vso/ns#>.
@prefix dbpedia-owl: <http://dbpedia.org/ontology/>.
gbfs:last_updated rdf:type xsd:integer;
rdfs:label "Last time the data in the feed was updated in POSIX time."@en.
gbfs:ttl rdf:type xsd:integer;
rdfs:label "Number of seconds before the data in the feed will be updated again (0 if the data should always be refreshed)."@en.
gbfs:version rdf:type xsd:string;
rdfs:label "GBFS version number to which the feed conforms, according to the versioning framework (added in v1.1)."@en.
gbfs:schema rdfs:range gbfs:Schema.
gbfs:Schema rdfs:hasProperty (<last_updated> <ttl> <version> <data>).
@prefix gbfs: <https://w3id.org/gbfs/terms>.
@prefix schema: <http://schema.org/#>.
@prefix ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix dcterms: <http://purl.org/dc/terms/>.
@prefix vs: <http://www.w3.org/2003/06/sw-vocab-status/ns#>.
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>.
@prefix vann: <http://purl.org/vocab/vann/>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix jsonsc: <https://www.w3.org/2019/wot/json-schema#>.
@prefix airs: <https://raw.githubusercontent.com/airs-linked-data/lov/latest/src/airs_vocabulary.ttl#>.
@prefix vso: <http://purl.org/vso/ns#>.
@prefix dbpedia-owl: <http://dbpedia.org/ontology/>.
{
"prefix": "sdm",
"jsonObjects": {
"sdm:Battery": "allOf",
"sdm:Type": "type",
"sdm:RefDevice": "refDevice",
"sdm:Status": "status",
"sdm:CycleLife": "cycleLife",
"sdm:AutonomyTime": "autonomyTime",
"sdm:RechargeTime": "rechargeTime",
"sdm:AcPowerInput": "acPowerInput",
"sdm:AcPowerOutput": "acPowerOutput",
"sdm:DcPowerInput": "dcPowerInput",
"sdm:DcPowerOutput": "dcPowerOutput"
},
"sources": {
"./SmartDataModels/battery.json": "sdm:Battery"
},
"shaclTargets": {
"sdm:Battery": ""
},
"shaclRoot": "",
"prefixes": {
"sdm": "https://smart-data-models.github.io/dataModel.Energy/ThreePhaseAcMeasurement/terms",
"schema": "http://schema.org/#",
"ebucore": "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"foaf": "http://xmlns.com/foaf/0.1/",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"dcterms": "http://purl.org/dc/terms/",
"vs": "http://www.w3.org/2003/06/sw-vocab-status/ns#",
"geo": "http://www.w3.org/2003/01/geo/wgs84_pos#",
"vann": "http://purl.org/vocab/vann/",
"owl": "http://www.w3.org/2002/07/owl#",
"jsonsc": "https://www.w3.org/2019/wot/json-schema#",
"airs": "https://raw.githubusercontent.com/airs-linked-data/lov/latest/src/airs_vocabulary.ttl#",
"vso": "http://purl.org/vso/ns#",
"dbpedia-owl": "http://dbpedia.org/ontology/"
},
"terms": {
"description":"dcterms:description",
"type": "rdf:type",
"last_updated": "dcterms:modified" ,
"url": "schema:url",
"summary": "ebucore:summary",
"name": "foaf:name",
"short_name": "rdfs:label",
"lat": "geo:lat",
"lon": "geo:long",
"cross_street": "airs:locatedAtCrossStreet",
"post_code": "dbpedia-owl:postalCode",
"capacity": "dbpedia-owl:capacity",
"creditcard": "schema:CreditCard",
"phone": "foaf:phone",
"car": "schema:car"
},
"creators": {
"creator1": "https://pietercolpaert.be/#me",
"creator2": "https://www.linkedin.com/in/andrei-popescu/"
}
}
\ No newline at end of file
{
"prefix": "sdm",
"prefix": "sdm",
"jsonObjects": {
"sdm:ElectricalMeasurment": "allOf",
"sdm:RefDevice": "refDevice",
"sdm:RefTargetDevice": "refTargetDevice",
"sdm:ActiveEnergyImport": "activeEnergyImport",
"sdm:ReactiveEnergyImport": "reactiveEnergyImport",
"sdm:ApparentEnergyImport": "apparentEnergyImport",
"sdm:ActiveEnergyExport": "activeEnergyExport",
"sdm:ReactiveEnergyExport": "reactiveEnergyExport",
"sdm:ApparentEnergyExport": "apparentEnergyExport",
"sdm:ActivePower": "activePower",
"sdm:ReactivePower": "reactivePower",
"sdm:ApparentPower": "apparentPower",
"sdm:PowerFactor": "powerFactor",
"sdm:DisplacementPowerFactor": "displacementPowerFactor",
"sdm:Current": "current",
"sdm:PhaseVoltage": "phaseVoltage",
"sdm:PhaseToPhaseVoltage": "phaseToPhaseVoltage",
"sdm:ThdVoltage": "thdVoltage",
"sdm:ThdCurrent": "thdCurrent",
"sdm:L1": "L1",
"sdm:L2": "L2",
"sdm:L3": "L3"
},
"sources": {
"./SmartDataModels/dataModel.json": "sdm:ElectricalMeasurment"
"./SmartDataModels/dataModel.json": "sdm:ElectricalMeasurment",
"./SmartDataModels/battery.json": "sdm:Battery"
},
"shaclTargets": {
......
......@@ -20,7 +20,7 @@ var Traverse = /** @class */ (function () {
Traverse.initialise = function (writer) {
this.writer = writer;
};
Traverse.traverse = function (parentKey, schema, propertyList) {
Traverse.traverse = function (parentKey, schema) {
if (!schema) {
return;
}
......@@ -63,11 +63,11 @@ var Traverse = /** @class */ (function () {
if (schema.items != undefined) {
//
if (schema.items.type === 'object') {
this.traverse(parentKey, schema.items, []);
this.traverse(parentKey, schema.items);
//console.log("schema items", schema.items);
for (var _i = 0, _a = Object.keys(schema.items); _i < _a.length; _i++) {
var item = _a[_i];
this.traverse(item, schema.items[item], []);
this.traverse(item, schema.items[item]);
//console.log("item", item);
}
}
......@@ -82,22 +82,22 @@ var Traverse = /** @class */ (function () {
return;
}
if (schema.type === 'object') {
var propertyList_1 = [];
var propertyList = [];
console.log("object: ");
console.log("object schema", schema);
propertyList_1 = [];
propertyList = [];
if (schema.properties != undefined) {
// Recursive Step
for (var _b = 0, _c = Object.keys(schema.properties); _b < _c.length; _b++) {
var item = _c[_b];
propertyList_1.push(namedNode(item.toString()));
this.traverse(item, schema.properties[item], []);
propertyList.push(namedNode(item.toString()));
this.traverse(item, schema.properties[item]);
}
console.log("propertyLIst", propertyList_1);
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_1)));
propertyList_1 = [];
this.writer.addQuad(RDFTools.node_node_list(prefix + ':' + RDFTools.capitalizeFirstLetter(parentKey), 'rdfs:hasProperty', this.writer.list(propertyList)));
propertyList = [];
}
// if(schema.patternProperties != undefined // No support yet){
//}
......@@ -117,7 +117,7 @@ var Traverse = /** @class */ (function () {
// pass its components recursively to be further parsed
for (var _d = 0, _e = Object.keys(schema.allOf); _d < _e.length; _d++) {
var item = _e[_d];
this.traverse(item, schema.allOf[item], []);
this.traverse(item, schema.allOf[item]);
}
return;
}
......@@ -138,7 +138,7 @@ var Traverse = /** @class */ (function () {
if (schema.properties != undefined) {
for (var _f = 0, _g = Object.keys(schema.properties); _f < _g.length; _f++) {
var item = _g[_f];
this.traverse(item, schema.properties[item], []);
this.traverse(item, schema.properties[item]);
}
}
}
......
......@@ -28,7 +28,7 @@ static initialise (writer){
this.writer = writer;
}
static traverse (parentKey, schema, propertyList){
static traverse (parentKey, schema){
if (!schema) {
return;
}
......@@ -75,10 +75,10 @@ static traverse (parentKey, schema, propertyList){
if (schema.items != undefined){
//
if (schema.items.type === 'object'){
this.traverse(parentKey, schema.items, []);
this.traverse(parentKey, schema.items);
//console.log("schema items", schema.items);
for(let item of Object.keys(schema.items)){
this.traverse(item, schema.items[item], [])
this.traverse(item, schema.items[item])
//console.log("item", item);
}
}
......@@ -102,7 +102,7 @@ static traverse (parentKey, schema, propertyList){
// Recursive Step
for (let item of Object.keys(schema.properties)){
propertyList.push(namedNode(item.toString()));
this.traverse(item,schema.properties[item], [])
this.traverse(item,schema.properties[item])
}
console.log("propertyLIst", propertyList);
// key hasProperties propertyList
......@@ -129,7 +129,7 @@ static traverse (parentKey, schema, propertyList){
// Data must be valid against all its components;
// pass its components recursively to be further parsed
for (let item of Object.keys(schema.allOf)){
this.traverse(item,schema.allOf[item], [])
this.traverse(item,schema.allOf[item])
}
return;
}
......@@ -150,7 +150,7 @@ static traverse (parentKey, schema, propertyList){
*/
if(schema.properties != undefined){
for (let item of Object.keys(schema.properties)){
this.traverse(item,schema.properties[item], [])
this.traverse(item,schema.properties[item])
}
}
}
......
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