Commit 3b225ecd authored by Andrei Popescu's avatar Andrei Popescu
Browse files

recursive jsonProcessor under construction

parent a88125fa
Pipeline #54737 passed with stage
in 30 seconds
......@@ -13,11 +13,11 @@ export class JsonProcessor {
static jsonSchema: any;
static mainObject: any;
static mainJsonObject: any;
static fileName: any;
static rdf_json_objects = new Map<string, string>();
static termMap = new Map<string, string>();
static writer: any;
static path: any;
static properties: any;
static initialise ( source:string, mainObj: string ){
// Getting configuration elements
......@@ -33,51 +33,84 @@ export class JsonProcessor {
this.jsonSchema = require(source);
this.mainObject = mainObj;
this.mainJsonObject = this.getJsonObject(this.mainObject);
this.fileName = mainObj;
// 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
}
static callParseJsonRecursive(path){
let hiddenClasses:any[] = [];
let depth = 0;
let hiddenClasses = this.parseJsonRecursive(this.writer, depth, path);
this.parseJsonRecursive(this.writer, depth, path, this.mainJsonObject, this.properties);
//path ?
return hiddenClasses; // these will be modified
return // these will be modified
}
static parseJsonRecursive (writer, depth, path){
static parseJsonRecursive (writer, depth, path, mainJsonObject, properties){
if (depth > 2){ // base case
return
if (depth > 1){ // base case
return;
}
else{
for (const prop in properties){
if (this.termMap.has(prop)){
return // base case
let propType;
let subProperties;
let propDescription;
if (depth == 0){
propType = path[2].properties[prop].type;
subProperties = path[2].properties[prop].properties; //
propDescription = path[2].properties[prop].description;
let directEnum = path[2].properties[prop].enum;
let subSubProperties = path[2].properties[prop].properties;
let subSubItems = path[2].properties[prop].items;
}
if (depth == 1){
path = path[2].properties[mainJsonObject]; // adapt the path at depth 1 for the currently mainObject
propType = path.properties[prop].type;
subProperties = path.properties[prop].properties;
propDescription = path.properties[prop].description;
let directEnum = path.properties[prop].enum;
let subSubProperties = path.properties[prop].properties;
let subItems = path.properties[prop].items;
}
if (this.termMap.has(prop)){
return;// base case
}
else{
// Base cases
if(pattern4):
this.writer.addQuad(RDFTools.node_node_node('sdm:'+term, 'rdf:type', 'rdf:Property')); // Add the property and its label
return
if(pattern5):
writer.write
return
if(pattern6):
writer.write
return
// if(pattern4):
// this.writer.addQuad(RDFTools.node_node_node('sdm:'+term, 'rdf:type', 'rdf:Property')); // Add the property and its label
// return;
// Recursive calls
if(pattern1 or patter 2):
hiddenClasses = hiddenClasses.concat('sdm:'+newClassName);
writer.write
return
}
if(propType == 'object' || propType =='array'){
depth += 1;
this.writer.addQuad(RDFTools.node_node_node('sdm:'+prop, 'rdf:type', 'rdf:Property')); // Add the property and its label
const newClassName = RDFTools.capitalizeFirstLetter(prop); // Since it is an object/array, we give it a new class as a range
this.writer.addQuad(RDFTools.node_node_node('sdm:'+prop, 'rdfs:range', 'sdm:'+newClassName));
// set properties
// set path
// set mainJsonObject
// Recursive call if we are dealing with an object or an array, which have nested properties
this.parseJsonRecursive(writer, depth, path, mainJsonObject, properties);
return;
}
}
}
}
}
static getJsonObject (mainObject: string){
for(let entry of Array.from(this.rdf_json_objects.entries())){
const key = entry[0];
......@@ -87,4 +120,8 @@ export class JsonProcessor {
}
}
}
static getMainObject (){
return this.mainObject;
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ for (let [schema,object] of Array.from(schema_object)){
i +=1;
//const smdPattern = new SMDPattern(schema, object);
const smdPattern = new SMDPattern(schema, object);
RDFTools.initialise(smdPattern.getFileName());
ShaclTools.initialise(smdPattern.getFileName(), smdPattern.getRequiredProperties(), smdPattern.jsonSource, smdPattern.mainObject );
smdPattern.basicsToQuads();
......@@ -42,17 +42,14 @@ for (let [schema,object] of Array.from(schema_object)){
for schema, object in schema_object{
JsonProcessor.initialise(schema, object);
RDFTools.initialise(JsonProcessor.getMainObject().str()); //initialising the filename written by RDF tools with the name of the main object
smdPatter = new smdPattern(schema, object);
RDFTools.initialise(smdPattern.getFileName());
smdPattern.basicsToQuads();
hiddenClasses = JsonProcessor.callParseJsonRecursive(); //this method will need to recursively call the parse method.
//TODO: where to write these ? smdPattern.basicsToQuads();
JsonProcessor.callParseJsonRecursive(); //this method will need to recursively call the parse method.
}
......
......@@ -101,10 +101,9 @@ export class SMDPattern {
// GBFS
if(depth == 1){ // Then we need the path to the nested object/array
console.log(this.mainObject);
console.log(jsonobj);
path = path[2].properties[jsonobj];
console.log("path depth1", path);
//console.log("path depth1", path);
// the object has either properties or items/properties
if (path.properties == undefined){
properties = path.items.properties;
......@@ -133,22 +132,12 @@ export class SMDPattern {
// Some nested classes have no items, but directly properties. station_area in station_information requires this exception for example.
// If we are at the second iteration, we have variable structure: some objects have items.properties, some only .properties
if (depth > 0){
if(path.items == undefined ){
termType = path.properties[term].type; // dont confuse with initial path set for depth = 0, path has already been updated in the previous (if depth=1)
termProperties = path.properties[term].properties;
termDescription = path.properties[term].description;
directEnum = path.properties[term].enum;
subProperties = path.properties[term].properties;
subItems = path.properties[term].items;
}
else{
termType = path.properties[term].type;
termProperties = path.properties[term].properties;
termDescription = path.properties[term].description;
directEnum = path.properties[term].enum;
subProperties = path.properties[term].properties;
subItems = path.properties[term].items;
}
termType = path.properties[term].type;
termProperties = path.properties[term].properties;
termDescription = path.properties[term].description;
directEnum = path.properties[term].enum;
subProperties = path.properties[term].properties;
subItems = path.properties[term].items;
}
// Else we are at iteration 0 and we assume all having items.properties
else{
......@@ -334,125 +323,16 @@ export class SMDPattern {
return requiredMap;
}
getJsonObject (mainObject: string){
console.log("ciao", mainObject);
// Set the
for(let entry of Array.from(this.rdf_json_objects.entries())){
const key = entry[0];
const value = entry[1];
console.log(key, value);
if( key == mainObject){
console.log("inside", key);
return this.rdf_json_objects.get(key);
}
}
}
/*
getJsonObject (mainObject:string) {
switch(mainObject) {
case 'sdm:ElectricalMeasurment': {
return 'allOf';
break;
}
// ---- Nested classes ----
case 'sdm:RefDevice': {
return 'refDevice';
break;
}
case 'sdm:RefTargetDevice': {
return 'refTargetDevice';
break;
}
case 'sdm:ActiveEnergyImport': {
return 'activeEnergyImport';
break;
}
case 'sdm:ReactiveEnergyImport': {
return 'reactiveEnergyImport';
break;
}
case 'sdm:ApparentEnergyImport': {
return 'apparentEnergyImport';
break;
}
case 'sdm:ApparentEnergyImport': {
return 'apparentEnergyImport';
break;
}
case 'sdm:ApparentEnergyImport': {
return 'apparentEnergyImport';
break;
}
case 'sdm:ApparentEnergyImport': {
return 'apparentEnergyImport';
break;
}
case 'sdm:ActiveEnergyExport': {
return 'activeEnergyExport';
break;
}
case 'sdm:ReactiveEnergyExport': {
return 'reactiveEnergyExport';
break;
}
case 'sdm:ApparentEnergyExport': {
return 'apparentEnergyExport';
break;
}
case 'sdm:ActivePower': {
return 'activePower';
break;
}
case 'sdm:ReactivePower': {
return 'reactivePower';
break;
}
case 'sdm:ApparentPower': {
return 'apparentPower';
break;
}
case 'sdm:PowerFactor': {
return 'powerFactor';
break;
}
case 'sdm:DisplacementPowerFactor': {
return 'displacementPowerFactor';
break;
}
case 'sdm:Current': {
return 'current';
break;
}
case 'sdm:PhaseVoltage': {
return 'phaseVoltage';
break;
}
case 'sdm:PhaseToPhaseVoltage': {
return 'phaseToPhaseVoltage';
break;
}
case 'sdm:ThdVoltage': {
return 'thdVoltage';
break;
}
case 'sdm:ThdCurrent': {
return 'thdCurrent';
break;
}
}
}
*/
getFileName(){
return this.fileName;
}
......@@ -463,7 +343,7 @@ export class SMDPattern {
return this.shaclFileText;
}
setMainObject(mainObject: string){
this.mainObject= mainObject;
this.mainObject = mainObject;
}
......
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