Commit 79dbd5e5 authored by Andrei Popescu's avatar Andrei Popescu
Browse files

further fixes on the enum path

parent 1ce1b943
Pipeline #55699 passed with stage
in 26 seconds
......@@ -23,10 +23,12 @@ gbfs:user_types rdf:type rdf:Property;
rdfs:range gbfs:User_types.
gbfs:User_types rdf:type rdfs:Class.
gbfs:user_types rdfs:label "Array of member and nonmember value(s) indicating that this set of rental hours applies to either members or non-members only."@en.
gbfs:undefined owl:oneOf (<member> <nonmember>), (<member> <nonmember>).
gbfs:days rdf:type rdf:Property;
rdfs:range gbfs:Days.
gbfs:Days rdf:type rdfs:Class.
gbfs:days rdfs:label "An array of abbreviations (first 3 letters) of English names of the days of the week for which this object applies."@en.
gbfs:undefined owl:oneOf (<sun> <mon> <tue> <wed> <thu> <fri> <sat>), (<sun> <mon> <tue> <wed> <thu> <fri> <sat>).
gbfs:start_time rdfs:range xsd:string;
rdfs:label "Start time for the hours of operation of the system."@en.
gbfs:end_time rdfs:range xsd:string;
......
......@@ -25,10 +25,12 @@ gbfs:rental_methods rdf:type rdf:Property;
rdfs:range gbfs:Rental_methods.
gbfs:Rental_methods rdf:type rdfs:Class.
gbfs:rental_methods rdfs:label "Payment methods accepted at this station."@en.
gbfs:undefined owl:oneOf (<key> schema:CreditCard <paypass> <applepay> <androidpay> <transitcard> <accountnumber> foaf:phone).
gbfs:enum rdf:type rdf:Property;
rdfs:range gbfs:Enum.
gbfs:Enum rdf:type rdfs:Class.
gbfs:enum rdfs:label "Payment methods accepted at this station."@en.
gbfs:Enum owl:oneOf (<key> schema:CreditCard <paypass> <applepay> <androidpay> <transitcard> <accountnumber> foaf:phone).
gbfs:is_virtual_station rdfs:range xsd:boolean;
rdfs:label "Is this station a location with or without physical infrastructure? (added in v2.1-RC)"@en.
gbfs:station_area rdf:type rdf:Property;
......
......@@ -33,6 +33,7 @@ gbfs:return_type rdf:type rdf:Property;
rdfs:range gbfs:Return_type.
gbfs:Return_type rdf:type rdfs:Class.
gbfs:return_type rdfs:label "The conditions for returning the vehicle at the end of the trip added in v2.3-RC."@en.
gbfs:undefined owl:oneOf (<free_floating> <roundtrip_station> <any_station>), (<free_floating> <roundtrip_station> <any_station>).
gbfs:vehicle_assets rdf:type rdf:Property;
rdfs:range gbfs:Vehicle_assets.
gbfs:Vehicle_assets rdf:type rdfs:Class.
......
......@@ -24,7 +24,6 @@ var JsonProcessor = /** @class */ (function () {
this.jsonSchema = require(source);
this.mainObject = mainObj;
this.mainJsonObject = this.getJsonObject(this.mainObject);
console.log("MainJsonObject: ", this.mainJsonObject);
this.prefix = this.config.prefix;
// Set path (TODO: set from confi.json)
// SMD
......@@ -96,6 +95,8 @@ var JsonProcessor = /** @class */ (function () {
var propDescription;
var directEnum;
var oneOf;
console.log("MainJsonObject: ", mainJsonObject);
console.log("Depth", depth);
if (depth == 0) {
// SMD
/*
......@@ -114,6 +115,7 @@ var JsonProcessor = /** @class */ (function () {
oneOf = path.items.properties[prop].oneOf;
}
if (depth == 1) {
console.log("depth = 1");
// SMD
/*
tmpPath = path[2].properties[mainJsonObject]; // adapt the path at depth 1 for the currently mainObject
......@@ -136,13 +138,17 @@ var JsonProcessor = /** @class */ (function () {
propDescription = tmpPath.description;
directEnum = tmpPath["enum"];
oneOf = tmpPath.oneOf;
console.log("path", tmpPath);
console.log("directEnum", directEnum);
}
else {
propType = tmpPath.type;
subItems = tmpPath.items;
propDescription = tmpPath.description;
directEnum = tmpPath["enum"];
directEnum = subItems["enum"];
oneOf = tmpPath.oneOf;
console.log("path", tmpPath);
console.log("directEnum", directEnum);
}
}
// Base cases
......@@ -164,6 +170,11 @@ var JsonProcessor = /** @class */ (function () {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
}
// An enum can be defined within 'whatever' construct
if (directEnum != undefined) {
var quad_1 = JsonProcessor.getEnumerationQuad(directEnum, prop);
this.writer.addQuad(quad_1);
}
return;
}
if (propType == 'integer') {
......@@ -181,6 +192,11 @@ var JsonProcessor = /** @class */ (function () {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
}
// An enum can be defined within 'whatever' construct
if (directEnum != undefined) {
var quad_2 = JsonProcessor.getEnumerationQuad(directEnum, prop);
this.writer.addQuad(quad_2);
}
return;
}
if (propType == 'string') {
......@@ -198,11 +214,10 @@ var JsonProcessor = /** @class */ (function () {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
}
// There might be an enum
// An enum can be defined within 'whatever' construct
if (directEnum != undefined) {
console.log("directENum", directEnum);
var quad_1 = JsonProcessor.getEnumerationQuad(directEnum, prop);
this.writer.addQuad(quad_1);
var quad_3 = JsonProcessor.getEnumerationQuad(directEnum, prop);
this.writer.addQuad(quad_3);
}
return;
}
......@@ -221,26 +236,17 @@ var JsonProcessor = /** @class */ (function () {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclTypedProperty(prop, rdfTools_1.RDFTools.getXsdType(propType)) + '\n';
}
}
// An enum can be defined within 'whatever' construct
if (directEnum != undefined) {
var quad_4 = JsonProcessor.getEnumerationQuad(directEnum, prop);
this.writer.addQuad(quad_4);
}
return;
}
// Verify if there is a oneOf defined
if (oneOf != undefined) {
console.log("there is an enum", oneOf);
var oneOfValues = [];
for (var _i = 0, oneOf_1 = oneOf; _i < oneOf_1.length; _i++) {
var value = oneOf_1[_i];
var key = Object.keys(value);
//We get the values from the mapping, else we create new terms
if (this.termMap.has(value[key[0]])) {
oneOfValues.push(namedNode(this.termMap.get(value[key[0]]).toString()));
}
else {
oneOfValues.push(namedNode(value[key[0].toString()]));
}
}
console.log("oneOfValues", oneOfValues);
var subPropQuad = rdfTools_1.RDFTools.node_node_list(this.prefix + ':' + prop, 'owl:oneOf', this.writer.list(oneOfValues));
this.writer.addQuad(subPropQuad);
var quad_5 = JsonProcessor.getOneOfQuad(oneOf, prop);
this.writer.addQuad(quad_5);
return;
}
// Recursive step
......@@ -256,10 +262,6 @@ var JsonProcessor = /** @class */ (function () {
if (propDescription != undefined) {
this.writer.addQuad(rdfTools_1.RDFTools.node_node_literal(this.prefix + ':' + prop, 'rdfs:label', propDescription.toString()));
}
if (directEnum != undefined) {
var quad_2 = JsonProcessor.getEnumerationQuad(directEnum, newClassName);
this.writer.addQuad(quad_2);
}
// Shacl shape text
if (JsonProcessor.isRequired(prop)) {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclRequiredProperty(prop) + '\n';
......@@ -268,6 +270,10 @@ var JsonProcessor = /** @class */ (function () {
this.shaclFileText = this.shaclFileText + shaclTools_1.ShaclTools.getShaclProperty(prop) + '\n';
}
}
if (directEnum != undefined) {
var quad_6 = JsonProcessor.getEnumerationQuad(directEnum, newClassName);
this.writer.addQuad(quad_6);
}
depth += 1;
//mainJsonObject = JsonProcessor.getJsonObject(this.prefix+':'+ RDFTools.capitalizeFirstLetter(prop));
mainJsonObject = JsonProcessor.getJsonObject(this.prefix + ':' + newClassName);
......@@ -287,6 +293,35 @@ var JsonProcessor = /** @class */ (function () {
return;
};
// Auxiliary Methods
/**
* OneOf
* @param oneOf
* @param name
* @returns
*/
JsonProcessor.getOneOfQuad = function (oneOf, name) {
var oneOfValues = [];
for (var _i = 0, oneOf_1 = oneOf; _i < oneOf_1.length; _i++) {
var value = oneOf_1[_i];
var key = Object.keys(value);
//We get the values from the mapping, else we create new terms
if (this.termMap.has(value[key[0]])) {
oneOfValues.push(namedNode(this.termMap.get(value[key[0]]).toString()));
}
else {
oneOfValues.push(namedNode(value[key[0].toString()]));
}
}
console.log("oneOfValues", oneOfValues);
var subPropQuad = rdfTools_1.RDFTools.node_node_list(this.prefix + ':' + name, 'owl:oneOf', this.writer.list(oneOfValues));
return subPropQuad;
};
/**
* Enum
* @param directEnum
* @param name
* @returns
*/
JsonProcessor.getEnumerationQuad = function (directEnum, name) {
var oneOfValues = [];
for (var _i = 0, directEnum_1 = directEnum; _i < directEnum_1.length; _i++) {
......
......@@ -45,7 +45,6 @@ export class JsonProcessor {
this.jsonSchema = require(source);
this.mainObject = mainObj;
this.mainJsonObject = this.getJsonObject(this.mainObject);
console.log("MainJsonObject: ", this.mainJsonObject);
this.prefix = this.config.prefix;
// Set path (TODO: set from confi.json)
......@@ -125,6 +124,10 @@ export class JsonProcessor {
let directEnum;
let oneOf;
console.log("MainJsonObject: ", mainJsonObject);
console.log("Depth", depth);
if (depth == 0){
// SMD
......@@ -149,6 +152,7 @@ export class JsonProcessor {
}
if (depth == 1){
console.log("depth = 1");
// SMD
/*
tmpPath = path[2].properties[mainJsonObject]; // adapt the path at depth 1 for the currently mainObject
......@@ -173,22 +177,29 @@ export class JsonProcessor {
propDescription = tmpPath.description;
directEnum = tmpPath.enum;
oneOf = tmpPath.oneOf;
console.log("path", tmpPath);
console.log("directEnum", directEnum);
}
else{
propType = tmpPath.type;
subItems = tmpPath.items;
propDescription = tmpPath.description;
directEnum = tmpPath.enum;
directEnum = subItems.enum;
oneOf = tmpPath.oneOf;
console.log("path", tmpPath);
console.log("directEnum", directEnum);
}
}
// Base cases
if(depth > 2){
return;
}
if (propType == 'number'){
if (this.termMap.has(prop) == false) {
this.termMap.set(prop, this.prefix+':'+prop);
......@@ -204,6 +215,11 @@ export class JsonProcessor {
this.shaclFileText = this.shaclFileText+ShaclTools.getShaclTypedProperty(prop, RDFTools.getXsdType(propType))+'\n';
}
}
// An enum can be defined within 'whatever' construct
if (directEnum != undefined){
let quad = JsonProcessor.getEnumerationQuad(directEnum, prop);
this.writer.addQuad(quad);
}
return;
}
if (propType == 'integer'){
......@@ -221,6 +237,11 @@ export class JsonProcessor {
this.shaclFileText = this.shaclFileText+ShaclTools.getShaclTypedProperty(prop, RDFTools.getXsdType(propType))+'\n';
}
}
// An enum can be defined within 'whatever' construct
if (directEnum != undefined){
let quad = JsonProcessor.getEnumerationQuad(directEnum, prop);
this.writer.addQuad(quad);
}
return;
}
......@@ -239,18 +260,17 @@ export class JsonProcessor {
this.shaclFileText = this.shaclFileText+ShaclTools.getShaclTypedProperty(prop, RDFTools.getXsdType(propType))+'\n';
}
}
// There might be an enum
// An enum can be defined within 'whatever' construct
if (directEnum != undefined){
console.log("directENum", directEnum);
let quad = JsonProcessor.getEnumerationQuad(directEnum, prop);
this.writer.addQuad(quad);
}
return;
}
if (propType == 'boolean'){
if (this.termMap.has(prop) == false) {
this.termMap.set(prop, this.prefix+':'+prop);
......@@ -266,30 +286,18 @@ export class JsonProcessor {
this.shaclFileText = this.shaclFileText+ShaclTools.getShaclTypedProperty(prop, RDFTools.getXsdType(propType))+'\n';
}
}
// An enum can be defined within 'whatever' construct
if (directEnum != undefined){
let quad = JsonProcessor.getEnumerationQuad(directEnum, prop);
this.writer.addQuad(quad);
}
return;
}
// Verify if there is a oneOf defined
if (oneOf != undefined){
console.log("there is an enum", oneOf);
let oneOfValues:NamedNode[] = [];
for (const value of oneOf){
let key = Object.keys(value);
//We get the values from the mapping, else we create new terms
if (this.termMap.has(value[key[0]])) {
oneOfValues.push(namedNode(this.termMap.get(value[key[0]]).toString()));
}
else{
oneOfValues.push(namedNode(value[key[0].toString()]));
}
}
console.log("oneOfValues", oneOfValues);
let subPropQuad = RDFTools.node_node_list(this.prefix+':'+prop, 'owl:oneOf', this.writer.list(oneOfValues));
this.writer.addQuad(subPropQuad);
let quad = JsonProcessor.getOneOfQuad(oneOf, prop);
this.writer.addQuad(quad);
return;
}
......@@ -309,11 +317,8 @@ export class JsonProcessor {
if(propDescription != undefined ){
this.writer.addQuad(RDFTools.node_node_literal(this.prefix+':'+prop, 'rdfs:label', propDescription.toString()));
}
if (directEnum != undefined){
let quad = JsonProcessor.getEnumerationQuad(directEnum, newClassName);
this.writer.addQuad(quad);
}
// Shacl shape text
if (JsonProcessor.isRequired(prop)){
......@@ -323,6 +328,11 @@ export class JsonProcessor {
this.shaclFileText = this.shaclFileText+ShaclTools.getShaclProperty(prop)+'\n';
}
}
if (directEnum != undefined){
let quad = JsonProcessor.getEnumerationQuad(directEnum, newClassName);
this.writer.addQuad(quad);
}
depth += 1;
......@@ -337,6 +347,8 @@ export class JsonProcessor {
}
}
// An array can have sub items
if(subItems != undefined){
for (let item in subItems){
this.jsonTraverseRecursive( depth, path, mainJsonObject, item);
......@@ -349,6 +361,35 @@ export class JsonProcessor {
// Auxiliary Methods
/**
* OneOf
* @param oneOf
* @param name
* @returns
*/
static getOneOfQuad(oneOf, name){
let oneOfValues:NamedNode[] = [];
for (const value of oneOf){
let key = Object.keys(value);
//We get the values from the mapping, else we create new terms
if (this.termMap.has(value[key[0]])) {
oneOfValues.push(namedNode(this.termMap.get(value[key[0]]).toString()));
}
else{
oneOfValues.push(namedNode(value[key[0].toString()]));
}
}
console.log("oneOfValues", oneOfValues);
let subPropQuad = RDFTools.node_node_list(this.prefix+':'+name, 'owl:oneOf', this.writer.list(oneOfValues));
return subPropQuad;
}
/**
* Enum
* @param directEnum
* @param name
* @returns
*/
static getEnumerationQuad(directEnum, name){
let oneOfValues:NamedNode[] = [];
for (const value of directEnum){
......
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