@igea/oac_backend 1.0.51 → 1.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/models/converter.js +38 -9
package/package.json
CHANGED
package/src/models/converter.js
CHANGED
|
@@ -117,25 +117,35 @@ class Converter {
|
|
|
117
117
|
// Determina tag principale dall'rdf:type
|
|
118
118
|
const types = [...dataset.match(subject, rdf.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'))];
|
|
119
119
|
const tagUri = types.length ? types[0].object.value : subject.value;
|
|
120
|
-
|
|
120
|
+
let tagName = Converter.qnameLocal(tagUri);
|
|
121
|
+
|
|
122
|
+
const tagIsNumber = (typeof tagName === 'string' && tagName.trim() !== '' && !isNaN(tagName))
|
|
123
|
+
if(tagIsNumber) tagName = "_" + tagName; // Prefix numerici per XML
|
|
124
|
+
|
|
125
|
+
//console.log("Building node: " + tagName + " for subject: " + subject.value)
|
|
121
126
|
|
|
122
127
|
const elem = parent.ele(tagName).att('rdf:about', subject.value);
|
|
123
128
|
|
|
124
129
|
// Itera predicati
|
|
125
|
-
const preds = new Set(dataset.match(subject).map(q => q.predicate.value));
|
|
130
|
+
const preds = new Set(dataset.match(subject).toArray().map(q => q.predicate.value));
|
|
126
131
|
for (let p of Array.from(preds).sort()) {
|
|
127
132
|
const predName = Converter.qnameLocal(p);
|
|
128
|
-
console.log("predName: " + predName)
|
|
129
|
-
const objects = dataset.match(subject, rdf.namedNode(p)).map(q => q.object);
|
|
133
|
+
//console.log(">>> predName: " + predName)
|
|
134
|
+
const objects = dataset.match(subject, rdf.namedNode(p)).toArray().map(q => q.object);
|
|
130
135
|
|
|
131
136
|
for (let obj of objects) {
|
|
137
|
+
// Skip rdf:type as it's used for the tag name
|
|
138
|
+
if(predName === "type") continue;
|
|
139
|
+
|
|
132
140
|
const child = elem.ele(predName);
|
|
133
141
|
|
|
134
142
|
if (obj.termType === 'Literal') {
|
|
135
143
|
const lit = child.ele('rdfs:Literal').att('rdf:about', obj.value);
|
|
136
144
|
lit.ele('rdfs:label').txt(obj.value);
|
|
137
145
|
} else if (obj.termType === 'NamedNode' || obj.termType === 'BlankNode') {
|
|
146
|
+
|
|
138
147
|
Converter.buildNode(dataset, obj, child, visited);
|
|
148
|
+
|
|
139
149
|
} else {
|
|
140
150
|
child.txt(obj.value);
|
|
141
151
|
}
|
|
@@ -163,13 +173,32 @@ class Converter {
|
|
|
163
173
|
});
|
|
164
174
|
|
|
165
175
|
const visited = new Set();
|
|
166
|
-
const subjects = Array.from(new Set(dataset.map(q => q.subject.value)))
|
|
167
|
-
.map(uri => rdf.namedNode(uri))
|
|
168
|
-
.sort((a, b) => a.value.localeCompare(b.value));
|
|
169
176
|
|
|
170
|
-
|
|
177
|
+
const subjects = Array.from(
|
|
178
|
+
new Set(
|
|
179
|
+
dataset.toArray().map(q => q.subject.value)
|
|
180
|
+
)
|
|
181
|
+
).map(uri => rdf.namedNode(uri))
|
|
182
|
+
.sort((a, b) => a.value.localeCompare(b.value));
|
|
183
|
+
|
|
184
|
+
const objects = Array.from(
|
|
185
|
+
new Set(
|
|
186
|
+
dataset.toArray().map(q => q.object.value)
|
|
187
|
+
)
|
|
188
|
+
).map(uri => rdf.namedNode(uri))
|
|
189
|
+
.sort((a, b) => a.value.localeCompare(b.value));
|
|
190
|
+
|
|
191
|
+
for (let s of subjects) {
|
|
192
|
+
s["_isRoot"] = false;
|
|
193
|
+
if (objects.findIndex(o => o.value === s.value) == -1) {
|
|
194
|
+
s["_isRoot"] = true;
|
|
195
|
+
//console.log("Root subject: " + s.value);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
171
199
|
for (let s of subjects) {
|
|
172
|
-
|
|
200
|
+
if(s["_isRoot"])
|
|
201
|
+
Converter.buildNode(dataset, s, root, visited);
|
|
173
202
|
}
|
|
174
203
|
|
|
175
204
|
const xml = root.end({ prettyPrint: true });
|