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
b86ba1ac
Commit
b86ba1ac
authored
Mar 11, 2022
by
Andrei Popescu
Browse files
fixed oneOf
parent
e657c26d
Pipeline
#55677
passed with stage
in 24 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
build/gbfs:Bike.ttl
View file @
b86ba1ac
...
...
@@ -19,5 +19,5 @@
rdfs:
comment
"Describes the vehicles that are available for rent (as of v2.1-RC2)."
@en
;
vann:
preferredNamespaceUri
"https://w3id.org/sdm/terms/bikes#"
.
<https://w3id.org/sdm/terms/>
dcterms:
creator
<https://pietercolpaert.be/#me>
,
<https://www.linkedin.com/in/andrei-popescu/>
.
gbfs:
is_reserved
owl:
oneOf
_:
undefined
.
gbfs:
is_disabled
owl:
oneOf
_:
undefined
.
gbfs:
is_reserved
owl:
oneOf
(
<boolean>
<number>
)
.
gbfs:
is_disabled
owl:
oneOf
(
<boolean>
<number>
)
.
jsonProcessor.js
View file @
b86ba1ac
...
...
@@ -10,7 +10,6 @@ var JsonProcessor = /** @class */ (function () {
function
JsonProcessor
()
{
}
JsonProcessor
.
initialise
=
function
(
source
,
mainObj
)
{
console
.
log
(
"
CALL INITIALISE
"
);
// RDF Vocabulary -------------------------
// Getting configuration elements
for
(
var
object
in
this
.
config
.
jsonObjects
)
{
...
...
@@ -74,7 +73,7 @@ var JsonProcessor = /** @class */ (function () {
//this.mainJsonObject = JsonProcessor.getJsonObject(this.prefix+':'+ RDFTools.capitalizeFirstLetter(prop));
this
.
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
this
.
mainObject
);
//console.log("mainjson",this.mainJsonObject);
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
this
.
path
,
this
.
mainJsonObject
,
prop
);
this
.
jsonTraverseRecursive
(
depth
,
this
.
path
,
this
.
mainJsonObject
,
prop
);
}
;
return
;
...
...
@@ -88,7 +87,7 @@ var JsonProcessor = /** @class */ (function () {
* @param prop
* @returns
*/
JsonProcessor
.
jsonTraverseRecursive
=
function
(
writer
,
depth
,
path
,
mainJsonObject
,
prop
)
{
JsonProcessor
.
jsonTraverseRecursive
=
function
(
depth
,
path
,
mainJsonObject
,
prop
)
{
// We only deal to depths <= 1; the following setups take care of that.
var
tmpPath
;
var
propType
;
...
...
@@ -224,17 +223,17 @@ var JsonProcessor = /** @class */ (function () {
var
oneOfValues
=
[];
for
(
var
_i
=
0
,
oneOf_1
=
oneOf
;
_i
<
oneOf_1
.
length
;
_i
++
)
{
var
value
=
oneOf_1
[
_i
];
console
.
log
(
"
oneof value
"
,
value
);
var
key
=
Object
.
keys
(
value
);
//We get the values from the mapping, else we create new terms
if
(
this
.
termMap
.
has
(
value
))
{
oneOfValues
.
push
(
namedNode
(
this
.
termMap
.
get
(
value
.
toString
()))
)
;
if
(
this
.
termMap
.
has
(
value
[
key
[
0
]]
))
{
oneOfValues
.
push
(
namedNode
(
this
.
termMap
.
get
(
value
[
key
[
0
]])
.
toString
()));
}
else
{
oneOfValues
.
push
(
namedNode
(
value
));
oneOfValues
.
push
(
namedNode
(
value
[
key
[
0
].
toString
()]
));
}
}
console
.
log
(
"
this is the list of v
alues
"
,
oneOfValues
);
var
subPropQuad
=
rdfTools_1
.
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
prop
,
'
owl:oneOf
'
,
oneOfValues
);
console
.
log
(
"
oneOfV
alues
"
,
oneOfValues
);
var
subPropQuad
=
rdfTools_1
.
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
prop
,
'
owl:oneOf
'
,
this
.
writer
.
list
(
oneOfValues
)
)
;
this
.
writer
.
addQuad
(
subPropQuad
);
return
;
}
...
...
@@ -263,7 +262,7 @@ var JsonProcessor = /** @class */ (function () {
oneOfValues
.
push
(
namedNode
(
value
));
}
}
var
subPropQuad
=
rdfTools_1
.
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
newClassName
,
'
owl:oneOf
'
,
this
.
writer
.
list
(
oneOfValues
)
)
;
var
subPropQuad
=
rdfTools_1
.
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
newClassName
,
'
owl:oneOf
'
,
oneOfValues
);
this
.
writer
.
addQuad
(
subPropQuad
);
}
// Shacl shape text
...
...
@@ -280,13 +279,13 @@ var JsonProcessor = /** @class */ (function () {
// An object can have sub properties
if
(
subProperties
!=
undefined
)
{
for
(
var
prop_1
in
subProperties
)
{
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
prop_1
);
this
.
jsonTraverseRecursive
(
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
);
this
.
jsonTraverseRecursive
(
depth
,
path
,
mainJsonObject
,
item
);
}
}
}
...
...
jsonProcessor.ts
View file @
b86ba1ac
...
...
@@ -30,8 +30,6 @@ export class JsonProcessor {
static
shaclRoot
:
any
;
static
initialise
(
source
:
string
,
mainObj
:
string
){
console
.
log
(
"
CALL INITIALISE
"
);
// RDF Vocabulary -------------------------
// Getting configuration elements
for
(
let
object
in
this
.
config
.
jsonObjects
){
...
...
@@ -55,7 +53,6 @@ export class JsonProcessor {
//this.path = this.jsonSchema[this.mainJsonObject];
//this.properties = this.path[2].properties; // Path to the properties of the main object
// GBFS
this
.
path
=
this
.
jsonSchema
.
properties
.
data
.
properties
[
this
.
mainJsonObject
];
this
.
properties
=
this
.
path
.
items
.
properties
;
// Path to the properties of the main object
...
...
@@ -82,21 +79,14 @@ export class JsonProcessor {
this
.
targets
.
set
(
object
,
this
.
config
.
shaclTargets
[
object
]);
}
this
.
shaclFileText
=
""
;
// reset in case there are more schemas
this
.
shaclTargetClass
=
JsonProcessor
.
getShaclTarget
(
mainObj
);
// Create a ShaclShape object and insert the first entries
this
.
shaclFileText
=
this
.
shaclFileText
+
ShaclTools
.
shapeShaclRoot
(
this
.
shaclRoot
);
this
.
shaclFileText
=
this
.
shaclFileText
+
'
sh:targetClass
'
+
this
.
shaclTargetClass
+
'
;
\n
'
;
}
/**
*
* @returns
...
...
@@ -111,7 +101,7 @@ export class JsonProcessor {
//console.log("mainjson",this.mainJsonObject);
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
this
.
path
,
this
.
mainJsonObject
,
prop
);
this
.
jsonTraverseRecursive
(
depth
,
this
.
path
,
this
.
mainJsonObject
,
prop
);
};
return
;
}
...
...
@@ -125,7 +115,7 @@ export class JsonProcessor {
* @param prop
* @returns
*/
static
jsonTraverseRecursive
(
writer
,
depth
,
path
,
mainJsonObject
,
prop
){
static
jsonTraverseRecursive
(
depth
,
path
,
mainJsonObject
,
prop
){
// We only deal to depths <= 1; the following setups take care of that.
let
tmpPath
;
let
propType
;
...
...
@@ -277,18 +267,20 @@ export class JsonProcessor {
console
.
log
(
"
there is an enum
"
,
oneOf
);
let
oneOfValues
:
NamedNode
[]
=
[];
for
(
const
value
of
oneOf
){
console
.
log
(
"
oneof value
"
,
value
);
let
key
=
Object
.
keys
(
value
);
//We get the values from the mapping, else we create new terms
if
(
this
.
termMap
.
has
(
value
))
{
oneOfValues
.
push
(
namedNode
(
this
.
termMap
.
get
(
value
.
toString
()))
)
;
if
(
this
.
termMap
.
has
(
value
[
key
[
0
]]
))
{
oneOfValues
.
push
(
namedNode
(
this
.
termMap
.
get
(
value
[
key
[
0
]])
.
toString
()));
}
else
{
oneOfValues
.
push
(
namedNode
(
value
));
oneOfValues
.
push
(
namedNode
(
value
[
key
[
0
].
toString
()]
));
}
}
console
.
log
(
"
this is the list of values
"
,
oneOfValues
);
let
subPropQuad
=
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
prop
,
'
owl:oneOf
'
,
oneOfValues
);
console
.
log
(
"
oneOfValues
"
,
oneOfValues
);
let
subPropQuad
=
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
prop
,
'
owl:oneOf
'
,
this
.
writer
.
list
(
oneOfValues
));
this
.
writer
.
addQuad
(
subPropQuad
);
return
;
}
...
...
@@ -320,7 +312,8 @@ export class JsonProcessor {
oneOfValues
.
push
(
namedNode
(
value
));
}
}
let
subPropQuad
=
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
newClassName
,
'
owl:oneOf
'
,
this
.
writer
.
list
(
oneOfValues
));
let
subPropQuad
=
RDFTools
.
node_node_list
(
this
.
prefix
+
'
:
'
+
newClassName
,
'
owl:oneOf
'
,
oneOfValues
);
this
.
writer
.
addQuad
(
subPropQuad
);
}
// Shacl shape text
...
...
@@ -341,13 +334,13 @@ export class JsonProcessor {
// An object can have sub properties
if
(
subProperties
!=
undefined
){
for
(
let
prop
in
subProperties
){
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
prop
);
this
.
jsonTraverseRecursive
(
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
);
this
.
jsonTraverseRecursive
(
depth
,
path
,
mainJsonObject
,
item
);
}
}
}
...
...
main.js
View file @
b86ba1ac
...
...
@@ -16,7 +16,6 @@ for (var _i = 0, _a = Array.from(schema_object); _i < _a.length; _i++) {
var
_b
=
_a
[
_i
],
schema
=
_b
[
0
],
object
=
_b
[
1
];
jsonProcessor_1
.
JsonProcessor
.
initialise
(
schema
,
object
);
rdfTools_1
.
RDFTools
.
initialise
(
jsonProcessor_1
.
JsonProcessor
.
getMainObject
());
//initialising the filename written by RDF tools with the name of the main object
console
.
log
(
"
Filenam
"
,
jsonProcessor_1
.
JsonProcessor
.
getMainObject
());
// filename ,
shaclTools_1
.
ShaclTools
.
initialise
(
jsonProcessor_1
.
JsonProcessor
.
getMainObject
(),
jsonProcessor_1
.
JsonProcessor
.
mainObject
);
jsonProcessor_1
.
JsonProcessor
.
callJsonTraverseRecursive
();
...
...
main.ts
View file @
b86ba1ac
...
...
@@ -12,19 +12,11 @@ for( let object in config.sources){
}
// main Function for recursive jsonProcessor
for
(
let
[
schema
,
object
]
of
Array
.
from
(
schema_object
)){
JsonProcessor
.
initialise
(
schema
,
object
);
RDFTools
.
initialise
(
JsonProcessor
.
getMainObject
());
//initialising the filename written by RDF tools with the name of the main object
// filename ,
ShaclTools
.
initialise
(
JsonProcessor
.
getMainObject
(),
JsonProcessor
.
mainObject
);
JsonProcessor
.
callJsonTraverseRecursive
();
RDFTools
.
writeTurtle
(
JsonProcessor
.
getWriter
());
ShaclTools
.
writeShacl
(
JsonProcessor
.
getMainObject
(),
JsonProcessor
.
getShaclFileText
());
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment