Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Andrei Popescu
JsonSchemaToRDF
Commits
1d6f78b6
Commit
1d6f78b6
authored
Mar 07, 2022
by
Andrei Popescu
Browse files
RDF vocab completed; working on the shacl shape
parent
4279081f
Pipeline
#54948
passed with stage
in 1 minute and 41 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
build/sdm:ElectricalMeasurment.ttl
View file @
1d6f78b6
...
...
@@ -15,6 +15,10 @@
@prefix
vso:
<http://purl.org/vso/ns#>
.
@prefix
dbpedia-owl:
<http://dbpedia.org/ontology/>
.
<https://w3id.org/sdm/terms/allOf>
rdf:
type
foaf:
Document
;
rdfs:
comment
"An electrical measurement from a system that uses three phase alternating current."
@en
;
vann:
preferredNamespaceUri
"https://w3id.org/sdm/terms/allOf#"
.
<https://w3id.org/sdm/terms/>
dcterms:
creator
<https://pietercolpaert.be/#me>
,
<https://www.linkedin.com/in/andrei-popescu/>
.
sdm:
refDevice
rdf:
type
rdf:
Property
;
rdfs:
range
sdm:
RefDevice
;
rdfs:
label
"Relationship. Device(s) used to obtain the measurement."
@en
.
...
...
build/sdm:ElectricalMeasurmentshacl.ttl
0 → 100644
View file @
1d6f78b6
undefined
<https://w3id.org/gbfs/shapes/>
a
sh:
NodeShape
;
sh:
targetClass
undefined
;
sh:
property
[
sh:
path
<refDevice>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<refTargetDevice>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<totalActiveEnergyImport>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<totalReactiveEnergyImport>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<totalApparentEnergyImport>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<totalActiveEnergyExport>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<totalReactiveEnergyExport>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<totalApparentEnergyExport>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<frequency>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<totalActivePower>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<totalReactivePower>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<totalApparentPower>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<activeEnergyImport>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<L1>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<L2>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<L3>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<reactiveEnergyImport>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<apparentEnergyImport>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<activeEnergyExport>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<reactiveEnergyExport>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<apparentEnergyExport>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<activePower>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<reactivePower>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<apparentPower>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<totalPowerFactor>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<powerFactor>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<totalDisplacementPowerFactor>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<displacementPowerFactor>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<current>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<N>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<phaseVoltage>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<phaseToPhaseVoltage>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<L12>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<L23>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<L31>
;
sh:
maxCount
1
;
sh:
datatype
xsd:
float
;
];
sh:
property
[
sh:
path
<thdVoltage>
;
sh:
maxCount
1
;
];
sh:
property
[
sh:
path
<thdCurrent>
;
sh:
maxCount
1
;
];
configs/config-smartdatamodel.json
View file @
1d6f78b6
{
"prefix"
:
"sdm"
,
"jsonObjects"
:
{
"sdm:ElectricalMeasurment"
:
"allOf"
,
"sdm:RefDevice"
:
"refDevice"
,
...
...
jsonProcessor.js
View file @
1d6f78b6
...
...
@@ -2,6 +2,7 @@
exports
.
__esModule
=
true
;
exports
.
JsonProcessor
=
void
0
;
var
rdfTools_1
=
require
(
"
./rdfTools
"
);
var
shaclTools_1
=
require
(
"
./shaclTools
"
);
var
N3
=
require
(
'
n3
'
);
var
DataFactory
=
N3
.
DataFactory
;
var
namedNode
=
DataFactory
.
namedNode
,
literal
=
DataFactory
.
literal
,
defaultGraph
=
DataFactory
.
defaultGraph
,
quad
=
DataFactory
.
quad
;
...
...
@@ -22,14 +23,32 @@ var JsonProcessor = /** @class */ (function () {
this
.
jsonSchema
=
require
(
source
);
this
.
mainObject
=
mainObj
;
this
.
mainJsonObject
=
this
.
getJsonObject
(
this
.
mainObject
);
this
.
prefix
=
this
.
config
.
prefix
;
// 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
//
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
'
https://w3id.org/sdm/terms/
'
+
this
.
mainJsonObject
,
'
rdf:type
'
,
'
foaf:Document
'
));
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_literal
(
'
https://w3id.org/sdm/terms/
'
+
this
.
mainJsonObject
,
'
rdfs:comment
'
,
this
.
jsonSchema
.
description
));
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_literal
(
'
https://w3id.org/sdm/terms/
'
+
this
.
mainJsonObject
,
'
vann:preferredNamespaceUri
'
,
'
https://w3id.org/sdm/terms/
'
+
this
.
mainJsonObject
+
'
#
'
));
for
(
var
creator
in
this
.
config
.
creators
)
{
console
.
log
(
"
creator
"
,
creator
);
this
.
creators
.
push
(
creator
);
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
'
https://w3id.org/sdm/terms/
'
,
'
dcterms:creator
'
,
this
.
config
.
creators
[
creator
]));
}
// Setting a map containing < requiredProp, existingTermForRequiredProp>.
for
(
var
_i
=
0
,
_a
=
this
.
jsonSchema
.
required
;
_i
<
_a
.
length
;
_i
++
)
{
var
requiredProp
=
_a
[
_i
];
this
.
requiredMap
.
set
(
requiredProp
.
toString
(),
this
.
termMap
.
get
(
requiredProp
.
toString
()));
}
// Create a ShaclShape object and insert the first entries
this
.
shaclFileText
=
this
.
shaclFileText
+
shaclTools_1
.
ShaclTools
.
getShaclRoot
();
this
.
shaclFileText
=
this
.
shaclFileText
+
shaclTools_1
.
ShaclTools
.
getShaclTargetClass
()
+
'
\n
'
;
};
JsonProcessor
.
callJsonTraverseRecursive
=
function
()
{
var
depth
=
0
;
for
(
var
prop
in
this
.
properties
)
{
this
.
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
'
sdm
:
'
+
rdfTools_1
.
RDFTools
.
capitalizeFirstLetter
(
prop
));
this
.
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
this
.
prefix
+
'
:
'
+
rdfTools_1
.
RDFTools
.
capitalizeFirstLetter
(
prop
));
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
this
.
path
,
this
.
mainJsonObject
,
prop
);
}
;
...
...
@@ -45,17 +64,13 @@ var JsonProcessor = /** @class */ (function () {
var
directEnum
;
if
(
depth
==
0
)
{
propType
=
path
[
2
].
properties
[
prop
].
type
;
subProperties
=
path
[
2
].
properties
[
prop
].
properties
;
//
subProperties
=
path
[
2
].
properties
[
prop
].
properties
;
subItems
=
path
[
2
].
properties
[
prop
].
items
;
propDescription
=
path
[
2
].
properties
[
prop
].
description
;
directEnum
=
path
[
2
].
properties
[
prop
][
"
enum
"
];
//let subSubProperties = path[2].properties[prop].properties;
}
if
(
depth
==
1
)
{
tmpPath
=
path
[
2
].
properties
[
mainJsonObject
];
// adapt the path at depth 1 for the currently mainObject
console
.
log
(
mainJsonObject
);
console
.
log
(
"
property
"
,
prop
);
console
.
log
(
"
prop
"
,
tmpPath
);
if
(
tmpPath
.
properties
!=
undefined
)
{
propType
=
tmpPath
.
properties
[
prop
].
type
;
subProperties
=
tmpPath
.
properties
;
...
...
@@ -65,9 +80,7 @@ var JsonProcessor = /** @class */ (function () {
subItems
=
tmpPath
.
items
[
prop
];
directEnum
=
tmpPath
.
items
[
prop
][
"
enum
"
];
}
console
.
log
(
"
proptype
"
,
propType
);
propDescription
=
tmpPath
.
description
;
//let subSubProperties = path.properties[prop].properties;
}
// Base cases
if
(
depth
>
2
)
{
...
...
@@ -76,9 +89,16 @@ var JsonProcessor = /** @class */ (function () {
if
(
propType
==
'
number
'
)
{
if
(
this
.
termMap
.
has
(
prop
)
==
false
)
{
this
.
termMap
.
set
(
prop
,
'
sdm:
'
+
prop
);
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
'
sdm
:
'
+
prop
,
'
rdfs:range
'
,
'
xsd:integer
'
));
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:range
'
,
'
xsd:integer
'
));
if
(
propDescription
!=
undefined
)
{
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_literal
(
'
sdm:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_literal
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
}
// Shacl shape text
if
(
shaclTools_1
.
ShaclTools
.
isRequired
(
prop
))
{
this
.
shaclFileText
=
this
.
shaclFileText
+
shaclTools_1
.
ShaclTools
.
getShaclTypedRequiredProperty
(
prop
,
rdfTools_1
.
RDFTools
.
getXsdType
(
propType
))
+
'
\n
'
;
}
else
{
this
.
shaclFileText
=
this
.
shaclFileText
+
shaclTools_1
.
ShaclTools
.
getShaclTypedProperty
(
prop
,
rdfTools_1
.
RDFTools
.
getXsdType
(
propType
))
+
'
\n
'
;
}
}
return
;
...
...
@@ -86,9 +106,16 @@ var JsonProcessor = /** @class */ (function () {
if
(
propType
==
'
boolean
'
)
{
if
(
this
.
termMap
.
has
(
prop
)
==
false
)
{
this
.
termMap
.
set
(
prop
,
'
sdm:
'
+
prop
);
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
'
sdm
:
'
+
prop
,
'
rdfs:range
'
,
'
xsd:boolean
'
));
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:range
'
,
'
xsd:boolean
'
));
if
(
propDescription
!=
undefined
)
{
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_literal
(
'
sdm:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_literal
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
}
// Shacl shape text
if
(
shaclTools_1
.
ShaclTools
.
isRequired
(
prop
))
{
this
.
shaclFileText
=
this
.
shaclFileText
+
shaclTools_1
.
ShaclTools
.
getShaclTypedRequiredProperty
(
prop
,
rdfTools_1
.
RDFTools
.
getXsdType
(
propType
))
+
'
\n
'
;
}
else
{
this
.
shaclFileText
=
this
.
shaclFileText
+
shaclTools_1
.
ShaclTools
.
getShaclTypedProperty
(
prop
,
rdfTools_1
.
RDFTools
.
getXsdType
(
propType
))
+
'
\n
'
;
}
}
return
;
...
...
@@ -96,12 +123,12 @@ var JsonProcessor = /** @class */ (function () {
// Recursive step
if
(
propType
==
'
object
'
||
propType
==
'
array
'
)
{
if
(
this
.
termMap
.
has
(
prop
)
==
false
)
{
this
.
termMap
.
set
(
prop
,
'
sdm
:
'
+
prop
);
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
'
sdm
:
'
+
prop
,
'
rdf:type
'
,
'
rdf:Property
'
));
// Add the property and its label
this
.
termMap
.
set
(
prop
,
this
.
prefix
+
'
:
'
+
prop
);
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdf:type
'
,
'
rdf:Property
'
));
// Add the property and its label
var
newClassName
=
rdfTools_1
.
RDFTools
.
capitalizeFirstLetter
(
prop
);
// Since it is an object/array, we give it a new class as a range
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
'
sdm
:
'
+
prop
,
'
rdfs:range
'
,
'
sdm
:
'
+
newClassName
));
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:range
'
,
this
.
prefix
+
'
:
'
+
newClassName
));
if
(
propDescription
!=
undefined
)
{
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_literal
(
'
sdm
:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_literal
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
}
if
(
directEnum
!=
undefined
)
{
var
oneOfValues
=
[];
...
...
@@ -116,18 +143,26 @@ var JsonProcessor = /** @class */ (function () {
}
}
console
.
log
(
"
this is the list of values
"
,
oneOfValues
);
var
subPropQuad
=
rdfTools_1
.
RDFTools
.
node_node_list
(
'
sdm
:
'
+
newClassName
,
'
owl:oneOf
'
,
this
.
writer
.
list
(
oneOfValues
));
var
subPropQuad
=
rdfTools_1
.
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
newClassName
,
'
owl:oneOf
'
,
this
.
writer
.
list
(
oneOfValues
));
this
.
writer
.
addQuad
(
subPropQuad
);
}
// Shacl shape text
if
(
shaclTools_1
.
ShaclTools
.
isRequired
(
prop
))
{
this
.
shaclFileText
=
this
.
shaclFileText
+
shaclTools_1
.
ShaclTools
.
getShaclRequiredProperty
(
prop
)
+
'
\n
'
;
}
else
{
// Else the property is not required
this
.
shaclFileText
=
this
.
shaclFileText
+
shaclTools_1
.
ShaclTools
.
getShaclProperty
(
prop
)
+
'
\n
'
;
}
}
depth
+=
1
;
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
'
sdm
:
'
+
rdfTools_1
.
RDFTools
.
capitalizeFirstLetter
(
prop
));
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
this
.
prefix
+
'
:
'
+
rdfTools_1
.
RDFTools
.
capitalizeFirstLetter
(
prop
));
// An object can have sub properties
if
(
subProperties
!=
undefined
)
{
for
(
var
prop_1
in
subProperties
)
{
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
prop_1
);
}
}
// An array can have sub items
if
(
subItems
!=
undefined
)
{
for
(
var
item
in
subItems
)
{
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
item
);
...
...
@@ -149,6 +184,12 @@ var JsonProcessor = /** @class */ (function () {
JsonProcessor
.
getMainObject
=
function
()
{
return
this
.
mainObject
;
};
JsonProcessor
.
getRequiredProperties
=
function
()
{
return
this
.
requiredMap
;
};
JsonProcessor
.
getShaclFileText
=
function
()
{
return
this
.
shaclFileText
;
};
JsonProcessor
.
getWriter
=
function
()
{
return
this
.
writer
;
};
...
...
@@ -157,6 +198,9 @@ var JsonProcessor = /** @class */ (function () {
JsonProcessor
.
config
=
require
(
'
./configs/config-smartdatamodel.json
'
);
JsonProcessor
.
rdf_json_objects
=
new
Map
();
JsonProcessor
.
termMap
=
new
Map
();
JsonProcessor
.
creators
=
[];
// Shacl-related
JsonProcessor
.
requiredMap
=
new
Map
();
return
JsonProcessor
;
}());
exports
.
JsonProcessor
=
JsonProcessor
;
jsonProcessor.ts
View file @
1d6f78b6
import
{
RDFTools
}
from
"
./rdfTools
"
;
import
{
ShaclTools
}
from
'
./shaclTools
'
;
import
{
NamedNode
}
from
"
n3/lib/N3DataFactory
"
;
const
N3
=
require
(
'
n3
'
);
const
{
DataFactory
}
=
N3
;
const
{
namedNode
,
literal
,
defaultGraph
,
quad
}
=
DataFactory
;
export
class
JsonProcessor
{
// From config.json, we get:
// prefixes, terms, , schema_objects(in the main)
static
config
=
require
(
'
./configs/config-smartdatamodel.json
'
);
...
...
@@ -20,32 +18,53 @@ export class JsonProcessor {
static
writer
:
any
;
static
path
:
any
;
static
properties
:
any
;
static
prefix
:
any
;
static
creators
:
any
[]
=
[];
// Shacl-related
static
requiredMap
=
new
Map
<
string
,
string
>
();
static
shaclFileText
:
any
;
static
initialise
(
source
:
string
,
mainObj
:
string
){
// Getting configuration elements
for
(
let
object
in
this
.
config
.
jsonObjects
){
for
(
let
object
in
this
.
config
.
jsonObjects
){
this
.
rdf_json_objects
.
set
(
object
,
this
.
config
.
jsonObjects
[
object
]);
}
for
(
let
object
in
this
.
config
.
terms
){
for
(
let
object
in
this
.
config
.
terms
){
this
.
termMap
.
set
(
object
,
this
.
config
.
terms
[
object
]);
}
this
.
writer
=
new
N3
.
Writer
({
prefixes
:
this
.
config
.
prefixes
});
// Setting up basic info
this
.
jsonSource
=
source
;
// Needed when creating a ShaclShape object
this
.
jsonSchema
=
require
(
source
);
this
.
mainObject
=
mainObj
;
this
.
mainJsonObject
=
this
.
getJsonObject
(
this
.
mainObject
);
this
.
prefix
=
this
.
config
.
prefix
;
// 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
//
this
.
writer
.
addQuad
(
RDFTools
.
node_node_node
(
'
https://w3id.org/sdm/terms/
'
+
this
.
mainJsonObject
,
'
rdf:type
'
,
'
foaf:Document
'
));
this
.
writer
.
addQuad
(
RDFTools
.
node_node_literal
(
'
https://w3id.org/sdm/terms/
'
+
this
.
mainJsonObject
,
'
rdfs:comment
'
,
this
.
jsonSchema
.
description
));
this
.
writer
.
addQuad
(
RDFTools
.
node_node_literal
(
'
https://w3id.org/sdm/terms/
'
+
this
.
mainJsonObject
,
'
vann:preferredNamespaceUri
'
,
'
https://w3id.org/sdm/terms/
'
+
this
.
mainJsonObject
+
'
#
'
));
for
(
let
creator
in
this
.
config
.
creators
){
console
.
log
(
"
creator
"
,
creator
)
this
.
creators
.
push
(
creator
);
this
.
writer
.
addQuad
(
RDFTools
.
node_node_node
(
'
https://w3id.org/sdm/terms/
'
,
'
dcterms:creator
'
,
this
.
config
.
creators
[
creator
]));
}
// Setting a map containing < requiredProp, existingTermForRequiredProp>.
for
(
const
requiredProp
of
this
.
jsonSchema
.
required
){
this
.
requiredMap
.
set
(
requiredProp
.
toString
(),
this
.
termMap
.
get
(
requiredProp
.
toString
())
);
}
// Create a ShaclShape object and insert the first entries
this
.
shaclFileText
=
this
.
shaclFileText
+
ShaclTools
.
getShaclRoot
();
this
.
shaclFileText
=
this
.
shaclFileText
+
ShaclTools
.
getShaclTargetClass
()
+
'
\n
'
;
}
static
callJsonTraverseRecursive
(){
let
depth
=
0
;
for
(
let
prop
in
this
.
properties
){
this
.
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
'
sdm
:
'
+
RDFTools
.
capitalizeFirstLetter
(
prop
));
this
.
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
this
.
prefix
+
'
:
'
+
RDFTools
.
capitalizeFirstLetter
(
prop
));
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
this
.
path
,
this
.
mainJsonObject
,
prop
);
};
return
;
...
...
@@ -59,20 +78,16 @@ export class JsonProcessor {
let
subItems
;
let
propDescription
;
let
directEnum
;
if
(
depth
==
0
){
propType
=
path
[
2
].
properties
[
prop
].
type
;
subProperties
=
path
[
2
].
properties
[
prop
].
properties
;
//
subProperties
=
path
[
2
].
properties
[
prop
].
properties
;
subItems
=
path
[
2
].
properties
[
prop
].
items
;
propDescription
=
path
[
2
].
properties
[
prop
].
description
;
directEnum
=
path
[
2
].
properties
[
prop
].
enum
;
//let subSubProperties = path[2].properties[prop].properties;
}
if
(
depth
==
1
){
tmpPath
=
path
[
2
].
properties
[
mainJsonObject
];
// adapt the path at depth 1 for the currently mainObject
console
.
log
(
mainJsonObject
);
console
.
log
(
"
property
"
,
prop
);
console
.
log
(
"
prop
"
,
tmpPath
);
if
(
tmpPath
.
properties
!=
undefined
){
propType
=
tmpPath
.
properties
[
prop
].
type
;
subProperties
=
tmpPath
.
properties
;
...
...
@@ -82,24 +97,26 @@ export class JsonProcessor {
subItems
=
tmpPath
.
items
[
prop
];
directEnum
=
tmpPath
.
items
[
prop
].
enum
;
}
console
.
log
(
"
proptype
"
,
propType
);
propDescription
=
tmpPath
.
description
;
//let subSubProperties = path.properties[prop].properties;
}
// Base cases
if
(
depth
>
2
){
return
;
}
if
(
propType
==
'
number
'
){
if
(
this
.
termMap
.
has
(
prop
)
==
false
)
{
this
.
termMap
.
set
(
prop
,
'
sdm:
'
+
prop
);
this
.
writer
.
addQuad
(
RDFTools
.
node_node_node
(
'
sdm
:
'
+
prop
,
'
rdfs:range
'
,
'
xsd:integer
'
));
this
.
writer
.
addQuad
(
RDFTools
.
node_node_node
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:range
'
,
'
xsd:integer
'
));
if
(
propDescription
!=
undefined
){
this
.
writer
.
addQuad
(
RDFTools
.
node_node_literal
(
'
sdm:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
this
.
writer
.
addQuad
(
RDFTools
.
node_node_literal
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
}
// Shacl shape text
if
(
ShaclTools
.
isRequired
(
prop
)){
this
.
shaclFileText
=
this
.
shaclFileText
+
ShaclTools
.
getShaclTypedRequiredProperty
(
prop
,
RDFTools
.
getXsdType
(
propType
))
+
'
\n
'
;
}
else
{
this
.
shaclFileText
=
this
.
shaclFileText
+
ShaclTools
.
getShaclTypedProperty
(
prop
,
RDFTools
.
getXsdType
(
propType
))
+
'
\n
'
;
}
}
return
;
...
...
@@ -107,9 +124,16 @@ export class JsonProcessor {
if
(
propType
==
'
boolean
'
){
if
(
this
.
termMap
.
has
(
prop
)
==
false
)
{
this
.
termMap
.
set
(
prop
,
'
sdm:
'
+
prop
);
this
.
writer
.
addQuad
(
RDFTools
.
node_node_node
(
'
sdm
:
'
+
prop
,
'
rdfs:range
'
,
'
xsd:boolean
'
));
this
.
writer
.
addQuad
(
RDFTools
.
node_node_node
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:range
'
,
'
xsd:boolean
'
));
if
(
propDescription
!=
undefined
){
this
.
writer
.
addQuad
(
RDFTools
.
node_node_literal
(
'
sdm:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
this
.
writer
.
addQuad
(
RDFTools
.
node_node_literal
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
}
// Shacl shape text
if
(
ShaclTools
.
isRequired
(
prop
)){
this
.
shaclFileText
=
this
.
shaclFileText
+
ShaclTools
.
getShaclTypedRequiredProperty
(
prop
,
RDFTools
.
getXsdType
(
propType
))
+
'
\n
'
;
}
else
{
this
.
shaclFileText
=
this
.
shaclFileText
+
ShaclTools
.
getShaclTypedProperty
(
prop
,
RDFTools
.
getXsdType
(
propType
))
+
'
\n
'
;
}
}
return
;
...
...
@@ -118,12 +142,12 @@ export class JsonProcessor {
// Recursive step
if
(
propType
==
'
object
'
||
propType
==
'
array
'
){
if
(
this
.
termMap
.
has
(
prop
)
==
false
)
{
this
.
termMap
.
set
(
prop
,
'
sdm
:
'
+
prop
);
this
.
writer
.
addQuad
(
RDFTools
.
node_node_node
(
'
sdm
:
'
+
prop
,
'
rdf:type
'
,
'
rdf:Property
'
));
// Add the property and its label
this
.
termMap
.
set
(
prop
,
this
.
prefix
+
'
:
'
+
prop
);
this
.
writer
.
addQuad
(
RDFTools
.
node_node_node
(
this
.
prefix
+
'
:
'
+
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
));
this
.
writer
.
addQuad
(
RDFTools
.
node_node_node
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:range
'
,
this
.
prefix
+
'
:
'
+
newClassName
));
if
(
propDescription
!=
undefined
){
this
.
writer
.
addQuad
(
RDFTools
.
node_node_literal
(
'
sdm
:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
this
.
writer
.
addQuad
(
RDFTools
.
node_node_literal
(
this
.
prefix
+
'
:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
}
if
(
directEnum
!=
undefined
){
let
oneOfValues
:
NamedNode
[]
=
[];
...
...
@@ -137,13 +161,19 @@ export class JsonProcessor {
}
}
console
.
log
(
"
this is the list of values
"
,
oneOfValues
);
let
subPropQuad
=
RDFTools
.
node_node_list
(
'
sdm
:
'
+
newClassName
,
'
owl:oneOf
'
,
this
.
writer
.
list
(
oneOfValues
));
let
subPropQuad
=
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
newClassName
,
'
owl:oneOf
'
,
this
.
writer
.
list
(
oneOfValues
));
this
.
writer
.
addQuad
(
subPropQuad
);
}
// Shacl shape text
if
(
ShaclTools
.
isRequired
(
prop
)){
this
.
shaclFileText
=
this
.
shaclFileText
+
ShaclTools
.
getShaclRequiredProperty
(
prop
)
+
'
\n
'
;
}
else
{
// Else the property is not required
this
.
shaclFileText
=
this
.
shaclFileText
+
ShaclTools
.
getShaclProperty
(
prop
)
+
'
\n
'
;
}
}
depth
+=
1
;
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
'
sdm
:
'
+
RDFTools
.
capitalizeFirstLetter
(
prop
));
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
this
.
prefix
+
'
:
'
+
RDFTools
.
capitalizeFirstLetter
(
prop
));
// An object can have sub properties
if
(
subProperties
!=
undefined
){
...
...
@@ -151,18 +181,18 @@ export class JsonProcessor {
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
prop
);
}
}
// An array can have sub items
if
(
subItems
!=
undefined
){
for
(
let
item
in
subItems
){
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
item
);
}
}
}
return
;
}
static
getJsonObject
(
mainObject
:
string
){
static
getJsonObject
(
mainObject
:
string
){
for
(
let
entry
of
Array
.
from
(
this
.
rdf_json_objects
.
entries
())){
const
key
=
entry
[
0
];
const
value
=
entry
[
1
];
...
...
@@ -171,10 +201,15 @@ export class JsonProcessor {
}
}
}
static
getMainObject
(){
static
getMainObject
(){
return
this
.
mainObject
;