Commit 063f8101 authored by Andrei Popescu's avatar Andrei Popescu
Browse files

fixed enum, class name, enum in string schema

- before implementing the features (term map,...), making sure tat the traversal is good
parent 185e62d2
Pipeline #56514 passed with stage
in 46 seconds
......@@ -15,20 +15,33 @@
@prefix vso: <http://purl.org/vso/ns#>.
@prefix dbpedia-owl: <http://dbpedia.org/ontology/>.
<last_updated> rdfs:range xsd:integer.
<ttl> rdfs:range xsd:integer.
<version> rdfs:range xsd:string.
<Stations> rdf:type rdfs:Class.
<station_id> rdfs:range xsd:string.
<name> rdfs:range xsd:string.
<ultrawarm> rdfs:range xsd:boolean.
<natural> rdfs:range xsd:boolean.
<coordinate_scale> rdfs:range xsd:integer.
<has_skylight> rdfs:range xsd:boolean.
<has_ceiling> rdfs:range xsd:boolean.
<ambient_light> rdfs:range xsd:integer.
<piglin_safe> rdfs:range xsd:boolean.
<bed_works> rdfs:range xsd:boolean.
<respawn_anchor_works> rdfs:range xsd:boolean.
<has_raids> rdfs:range xsd:boolean.
<logical_height> rdfs:range xsd:integer.
<min_y> rdfs:range xsd:integer.
<height> rdfs:range xsd:integer.
<infiniburn> rdfs:range xsd:string.
<effects> rdfs:range xsd:string.
<sdm:schema> rdfs:hasProperty (<name> <ultrawarm> <natural> <coordinate_scale> <has_skylight> <has_ceiling> <ambient_light> <fixed_time> <piglin_safe> <bed_works> <respawn_anchor_works> <has_raids> <logical_height> <min_y> <height> <infiniburn> <effects>).
<short_name> rdfs:range xsd:string.
<lat> rdfs:range xsd:integer.
<lon> rdfs:range xsd:integer.
<address> rdfs:range xsd:string.
<cross_street> rdfs:range xsd:string.
<region_id> rdfs:range xsd:string.
<post_code> rdfs:range xsd:string.
<Rental_methods> rdf:type rdfs:Class.
<sdm:rental_methods> owl:oneOf (<key> <creditcard> <paypass> <applepay> <androidpay> <transitcard> <accountnumber> <phone>).
<is_virtual_station> rdfs:range xsd:boolean.
<type> rdfs:range xsd:string.
<sdm:type> owl:oneOf (<MultiPolygon>).
<Coordinates> rdf:type rdfs:Class.
<sdm:Station_area> rdfs:hasProperty (<type> <coordinates>).
<capacity> rdfs:range xsd:integer.
<is_valet_station> rdfs:range xsd:boolean.
<is_charging_station> rdfs:range xsd:boolean.
<android> rdfs:range xsd:string.
<ios> rdfs:range xsd:string.
<web> rdfs:range xsd:string.
<sdm:Rental_uris> rdfs:hasProperty (<android> <ios> <web>).
<sdm:Stations> rdfs:hasProperty (<station_id> <name> <short_name> <lat> <lon> <address> <cross_street> <region_id> <post_code> <rental_methods> <is_virtual_station> <station_area> <capacity> <vehicle_capacity> <is_valet_station> <is_charging_station> <rental_uris> <vehicle_type_capacity>).
<sdm:Data> rdfs:hasProperty (<stations>).
<sdm:Schema> rdfs:hasProperty (<last_updated> <ttl> <version> <data>).
......@@ -9,48 +9,45 @@ var writer = new N3.Writer({ prefixes: config.prefixes });
var prefix = "sdm";
RDFTools.initialise("ElectricalMeasurement");
//let schema = require('./GBFS/system_pricing_plan.json');
//let schema = require('./GBFS/station_information.json');
var 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');
var schema = require('./GBFS/minecraft.json');
//let schema = require('./GBFS/minecraft.json');
function traverse(parentKey, schema, propertyList) {
if (!schema) {
return;
}
if (schema.type != undefined) {
if (schema.type != undefined) { // If the schema/sub-schema has a type
console.log("key: ", parentKey);
// Base cases
if (schema.type === 'string') { // Base Case
console.log("string: ");
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdfs:range', 'xsd:string'));
if (schema["enum"] != undefined) { // schema.enum can also be found in a string schema
writer.addQuad(getOneOfQuad(schema["enum"], parentKey));
return;
}
return parentKey;
}
if (schema.type === 'number') { // Base Case
console.log("number: ");
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdfs:range', 'xsd:integer'));
return parentKey;
}
if (schema.type === 'integer') { // Base Case
console.log("integer: ");
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdfs:range', 'xsd:integer'));
return parentKey;
}
if (schema.type === 'boolean') {
console.log("boolean: ");
if (schema.type === 'boolean') { // Base Case
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdfs:range', 'xsd:boolean'));
return parentKey;
}
if (schema["enum"] != undefined) {
console.log("enum: ");
writer.addQuad(getOneOfQuad(schema.items["enum"], parentKey));
// key oneOf <-,-,-,-,->
return;
if (schema["enum"] != undefined) { // Base Case: schema.enum
writer.addQuad(getOneOfQuad(schema["enum"], parentKey));
return parentKey;
}
if (schema.type === 'array') {
console.log("array: ");
console.log("array schema", schema);
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdf:type', 'rdfs:Class'));
writer.addQuad(RDFTools.node_node_node(RDFTools.capitalizeFirstLetter(parentKey), 'rdf:type', 'rdfs:Class'));
if (schema.items != undefined) {
//
if (schema.items.type === 'object') {
......@@ -62,7 +59,7 @@ function traverse(parentKey, schema, propertyList) {
//console.log("item", item);
}
}
if (schema.items["enum"] != undefined) { // If there is an enum
if (schema.items["enum"] != undefined) { // schema.items.enum
writer.addQuad(getOneOfQuad(schema.items["enum"], parentKey));
}
if (schema.items['$ref'] != undefined) { // No support for $ref
......@@ -86,7 +83,7 @@ function traverse(parentKey, schema, propertyList) {
}
console.log("propertyLIst", propertyList_1);
// key hasProperties propertyList
writer.addQuad(RDFTools.node_node_list(prefix + ':' + parentKey, 'rdfs:hasProperty', writer.list(propertyList_1)));
writer.addQuad(RDFTools.node_node_list(prefix + ':' + RDFTools.capitalizeFirstLetter(parentKey), 'rdfs:hasProperty', writer.list(propertyList_1)));
propertyList_1 = [];
}
// No return here otherwise the program stops
......@@ -109,10 +106,6 @@ function traverse(parentKey, schema, propertyList) {
}
return;
}
if (schema["enum"] != undefined) {
console.log("enum is defined", schema["enum"]);
// this can occur in different scenarios: how to manage?
}
}
else {
//Good luck managing arbitrary schemas.
......@@ -134,7 +127,7 @@ function traverse(parentKey, schema, propertyList) {
}
}
}
// If its none of the above
// If its none of the above: Danger Zone
return;
}
function getOneOfQuad(oneOf, name) {
......
......@@ -16,56 +16,50 @@ let prefix ="sdm";
RDFTools.initialise("ElectricalMeasurement");
//let schema = require('./GBFS/system_pricing_plan.json');
//let schema = require('./GBFS/station_information.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/minecraft.json');
function traverse (parentKey, schema, propertyList ){
function traverse (parentKey, schema, propertyList ){
if (!schema) {
return;
}
if (schema.type != undefined){
if (schema.type != undefined){ // If the schema/sub-schema has a type
console.log("key: ", parentKey);
// Base cases
if (schema.type === 'string') {// Base Case
console.log("string: ")
if (schema.type === 'string') { // Base Case
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdfs:range', 'xsd:string'));
if (schema.enum != undefined){ // schema.enum can also be found in a string schema
writer.addQuad(getOneOfQuad(schema.enum, parentKey));
return;
}
return parentKey;
}
if (schema.type === 'number') { // Base Case
console.log("number: ")
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdfs:range', 'xsd:integer'));
return parentKey;
}
if (schema.type === 'integer') {// Base Case
console.log("integer: ")
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdfs:range', 'xsd:integer'));
return parentKey;
}
if (schema.type === 'boolean') {
console.log("boolean: ")
if (schema.type === 'boolean') {// Base Case
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdfs:range', 'xsd:boolean'));
return parentKey;
}
if (schema.enum != undefined){
console.log("enum: ");
writer.addQuad(getOneOfQuad(schema.items.enum, parentKey));
// key oneOf <-,-,-,-,->
return;
if (schema.enum != undefined){ // Base Case: schema.enum
writer.addQuad(getOneOfQuad(schema.enum, parentKey));
return parentKey;
}
if (schema.type === 'array'){
console.log("array: ");
console.log("array schema", schema);
writer.addQuad(RDFTools.node_node_node(parentKey, 'rdf:type', 'rdfs:Class' ));
writer.addQuad(RDFTools.node_node_node(RDFTools.capitalizeFirstLetter(parentKey), 'rdf:type', 'rdfs:Class' ));
if (schema.items != undefined){
//
......@@ -77,10 +71,9 @@ function traverse (parentKey, schema, propertyList ){
//console.log("item", item);
}
}
if(schema.items.enum != undefined){// If there is an enum
if(schema.items.enum != undefined){// schema.items.enum
writer.addQuad(getOneOfQuad(schema.items.enum, parentKey));
}
if(schema.items['$ref'] != undefined){// No support for $ref
writer.addQuad(RDFTools.node_node_node(prefix+':'+parentKey, 'rdfs:hasProperty',schema.items['$ref'] ));
}
......@@ -102,7 +95,7 @@ function traverse (parentKey, schema, propertyList ){
}
console.log("propertyLIst", propertyList);
// key hasProperties propertyList
writer.addQuad(RDFTools.node_node_list(prefix+':'+parentKey, 'rdfs:hasProperty', writer.list(propertyList)));
writer.addQuad(RDFTools.node_node_list(prefix+':'+RDFTools.capitalizeFirstLetter(parentKey), 'rdfs:hasProperty', writer.list(propertyList)));
propertyList = [];
}
// No return here otherwise the program stops
......@@ -125,17 +118,10 @@ function traverse (parentKey, schema, propertyList ){
}
return;
}
if(schema.enum != undefined){
console.log("enum is defined", schema.enum);
// this can occur in different scenarios: how to manage?
}
}
else{
//Good luck managing arbitrary schemas.
/*
e.g.: properties:{} occuring in a construct with no type
allOf :[
......@@ -154,7 +140,7 @@ function traverse (parentKey, schema, propertyList ){
}
}
// If its none of the above
// If its none of the above: Danger Zone
return;
}
......@@ -169,5 +155,4 @@ function getOneOfQuad(oneOf, name){
}
traverse( 'schema',schema,[]);
RDFTools.writeTurtle(writer);
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