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
4279081f
Commit
4279081f
authored
Mar 07, 2022
by
Andrei Popescu
Browse files
added support for properties vs items
parent
5846bca1
Pipeline
#54917
passed with stage
in 24 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
jsonProcessor.js
View file @
4279081f
...
...
@@ -26,78 +26,6 @@ var JsonProcessor = /** @class */ (function () {
this
.
path
=
this
.
jsonSchema
[
this
.
mainJsonObject
];
this
.
properties
=
this
.
path
[
2
].
properties
;
// Path to the properties of the main object
};
JsonProcessor
.
callParseJsonRecursive
=
function
()
{
var
hiddenClasses
=
[];
var
depth
=
0
;
this
.
parseJsonRecursive
(
this
.
writer
,
depth
,
this
.
path
,
this
.
mainJsonObject
,
this
.
properties
);
//path ?
return
;
// these will be modified
};
JsonProcessor
.
parseJsonRecursive
=
function
(
writer
,
depth
,
path
,
mainJsonObject
,
properties
)
{
console
.
log
(
"
in method
"
);
if
(
depth
>
2
)
{
// base case
console
.
log
(
"
depth > 1
"
);
return
;
}
else
{
for
(
var
prop
in
properties
)
{
var
tmpPath
=
void
0
;
var
propType
=
void
0
;
var
subProperties
=
void
0
;
var
propDescription
=
void
0
;
console
.
log
(
"
depth
"
,
depth
,
"
prop
"
,
prop
);
if
(
depth
==
0
)
{
propType
=
path
[
2
].
properties
[
prop
].
type
;
subProperties
=
path
[
2
].
properties
[
prop
].
properties
;
//
propDescription
=
path
[
2
].
properties
[
prop
].
description
;
var
directEnum
=
path
[
2
].
properties
[
prop
][
"
enum
"
];
var
subSubProperties
=
path
[
2
].
properties
[
prop
].
properties
;
var
subSubItems
=
path
[
2
].
properties
[
prop
].
items
;
}
if
(
depth
==
1
)
{
console
.
log
(
"
depth
"
,
depth
);
console
.
log
(
mainJsonObject
);
console
.
log
(
"
path2
"
,
path
[
2
]);
tmpPath
=
path
[
2
].
properties
[
mainJsonObject
];
// adapt the path at depth 1 for the currently mainObject
console
.
log
(
"
tmppath
"
,
tmpPath
);
propType
=
tmpPath
.
type
;
subProperties
=
tmpPath
.
properties
;
propDescription
=
tmpPath
.
description
;
//let directEnum = path.properties[prop].enum;
//let subSubProperties = path.properties[prop].properties;
//let subItems = path.properties[prop].items;
}
if
(
this
.
termMap
.
has
(
prop
))
{
console
.
log
(
"
prop in map
"
,
prop
);
// DO nothin;
}
else
{
console
.
log
(
"
not in map prop:
"
,
prop
);
// Base cases
// if(pattern4):
// this.writer.addQuad(RDFTools.node_node_node('sdm:'+term, 'rdf:type', 'rdf:Property')); // Add the property and its label
// return;
// Recursive calls
console
.
log
(
propType
);
if
(
propType
==
'
object
'
||
propType
==
'
array
'
)
{
this
.
writer
.
addQuad
(
rdfTools_1
.
RDFTools
.
node_node_node
(
'
sdm:
'
+
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
));
depth
+=
1
;
console
.
log
(
"
depth increase
"
,
depth
);
// properties = ?;
//path = ?;
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
'
sdm:
'
+
rdfTools_1
.
RDFTools
.
capitalizeFirstLetter
(
prop
));
// Recursive call if we are dealing with an object or an array, which have nested properties
return
;
// return here?
}
}
console
.
log
(
"
exit if
"
);
}
}
return
;
};
JsonProcessor
.
callJsonTraverseRecursive
=
function
()
{
var
depth
=
0
;
for
(
var
prop
in
this
.
properties
)
{
...
...
@@ -112,28 +40,34 @@ var JsonProcessor = /** @class */ (function () {
var
tmpPath
;
var
propType
;
var
subProperties
;
var
subItems
;
var
propDescription
;
var
directEnum
;
if
(
depth
==
0
)
{
propType
=
path
[
2
].
properties
[
prop
].
type
;
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;
//let subSubItems = path[2].properties[prop].items;
}
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
);
propType
=
tmpPath
.
properties
[
prop
].
type
;
if
(
tmpPath
.
properties
!=
undefined
)
{
propType
=
tmpPath
.
properties
[
prop
].
type
;
subProperties
=
tmpPath
.
properties
;
}
if
(
tmpPath
.
items
!=
undefined
)
{
propType
=
tmpPath
.
items
[
prop
].
type
;
subItems
=
tmpPath
.
items
[
prop
];
directEnum
=
tmpPath
.
items
[
prop
][
"
enum
"
];
}
console
.
log
(
"
proptype
"
,
propType
);
subProperties
=
tmpPath
.
properties
;
propDescription
=
tmpPath
.
description
;
directEnum
=
tmpPath
.
properties
[
prop
][
"
enum
"
];
//let subSubProperties = path.properties[prop].properties;
//let subItems = path.properties[prop].items;
}
// Base cases
if
(
depth
>
2
)
{
...
...
@@ -188,8 +122,16 @@ var JsonProcessor = /** @class */ (function () {
}
depth
+=
1
;
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
'
sdm:
'
+
rdfTools_1
.
RDFTools
.
capitalizeFirstLetter
(
prop
));
for
(
var
prop_1
in
subProperties
)
{
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
prop_1
);
// An object can have sub properties
if
(
subProperties
!=
undefined
)
{
for
(
var
prop_1
in
subProperties
)
{
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
prop_1
);
}
}
if
(
subItems
!=
undefined
)
{
for
(
var
item
in
subItems
)
{
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
item
);
}
}
}
return
;
...
...
jsonProcessor.ts
View file @
4279081f
...
...
@@ -41,7 +41,7 @@ export class JsonProcessor {
this
.
properties
=
this
.
path
[
2
].
properties
;
// Path to the properties of the main object
}
static
callJsonTraverseRecursive
(){
let
depth
=
0
;
for
(
let
prop
in
this
.
properties
){
...
...
@@ -52,20 +52,20 @@ export class JsonProcessor {
}
static
jsonTraverseRecursive
(
writer
,
depth
,
path
,
mainJsonObject
,
prop
){
// We only deal to depths <= 1; the following setups take care of that.
let
tmpPath
;
let
propType
;
let
subProperties
;
let
subItems
;
let
propDescription
;
let
directEnum
;
if
(
depth
==
0
){
propType
=
path
[
2
].
properties
[
prop
].
type
;
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;
//let subSubItems = path[2].properties[prop].items;
}
if
(
depth
==
1
){
tmpPath
=
path
[
2
].
properties
[
mainJsonObject
];
// adapt the path at depth 1 for the currently mainObject
...
...
@@ -73,13 +73,19 @@ export class JsonProcessor {
console
.
log
(
mainJsonObject
);
console
.
log
(
"
property
"
,
prop
);
console
.
log
(
"
prop
"
,
tmpPath
);
propType
=
tmpPath
.
properties
[
prop
].
type
;
if
(
tmpPath
.
properties
!=
undefined
){
propType
=
tmpPath
.
properties
[
prop
].
type
;
subProperties
=
tmpPath
.
properties
;
}
if
(
tmpPath
.
items
!=
undefined
){
propType
=
tmpPath
.
items
[
prop
].
type
;
subItems
=
tmpPath
.
items
[
prop
];
directEnum
=
tmpPath
.
items
[
prop
].
enum
;
}
console
.
log
(
"
proptype
"
,
propType
);
subProperties
=
tmpPath
.
properties
;
propDescription
=
tmpPath
.
description
;
directEnum
=
tmpPath
.
properties
[
prop
].
enum
;
//let subSubProperties = path.properties[prop].properties;
//let subItems = path.properties[prop].items;
}
...
...
@@ -119,7 +125,6 @@ export class JsonProcessor {
if
(
propDescription
!=
undefined
){
this
.
writer
.
addQuad
(
RDFTools
.
node_node_literal
(
'
sdm:
'
+
prop
,
'
rdfs:label
'
,
propDescription
.
toString
()));
}
if
(
directEnum
!=
undefined
){
let
oneOfValues
:
NamedNode
[]
=
[];
for
(
const
value
of
directEnum
){
...
...
@@ -139,9 +144,20 @@ export class JsonProcessor {
}
depth
+=
1
;
mainJsonObject
=
JsonProcessor
.
getJsonObject
(
'
sdm:
'
+
RDFTools
.
capitalizeFirstLetter
(
prop
));
for
(
let
prop
in
subProperties
){
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
prop
);
}
// An object can have sub properties
if
(
subProperties
!=
undefined
){
for
(
let
prop
in
subProperties
){
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
prop
);
}
}
if
(
subItems
!=
undefined
){
for
(
let
item
in
subItems
){
this
.
jsonTraverseRecursive
(
this
.
writer
,
depth
,
path
,
mainJsonObject
,
item
);
}
}
}
return
;
}
...
...
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