@igea/oac_backend 1.0.97 → 1.0.98
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/controllers/fuseki.js +32 -43
package/package.json
CHANGED
|
@@ -226,85 +226,74 @@ router.get('/get-vocabolary-terms/:key', (req, res) => {
|
|
|
226
226
|
.pipe(res);
|
|
227
227
|
}else{
|
|
228
228
|
const rootIRI = `<http://diagnostica/vocabularies/${key}>`;
|
|
229
|
-
let _query = `PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
|
|
230
|
-
CONSTRUCT {
|
|
231
|
-
?concept ?p ?o .
|
|
232
|
-
}
|
|
233
|
-
WHERE {
|
|
234
|
-
?concept (crm:P127_has_broader_term*) ${rootIRI} .
|
|
235
|
-
?concept ?p ?o .
|
|
236
|
-
}`;
|
|
237
|
-
|
|
238
229
|
let query = `PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
|
|
239
230
|
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
240
|
-
|
|
241
|
-
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
|
242
|
-
|
|
243
|
-
CONSTRUCT {
|
|
244
|
-
|
|
245
|
-
?concept a owl:Class ;
|
|
246
|
-
rdfs:subClassOf ?parent ;
|
|
247
|
-
skos:prefLabel ?label ;
|
|
248
|
-
skos:closeMatch ?mappedConcept .
|
|
249
|
-
|
|
250
|
-
}
|
|
231
|
+
SELECT ?concept ?parent ?label
|
|
251
232
|
WHERE {
|
|
252
|
-
|
|
253
|
-
# Trovo tutti i concetti del vocabolario
|
|
254
233
|
?concept (crm:P127_has_broader_term*) ${rootIRI} .
|
|
255
|
-
|
|
256
|
-
# Recupero l'etichetta
|
|
257
234
|
OPTIONAL { ?concept rdfs:label ?label . }
|
|
258
|
-
|
|
259
|
-
# Prelevo il parent da broader term
|
|
260
|
-
OPTIONAL {
|
|
261
|
-
?concept crm:P127_has_broader_term ?parent .
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
# Genero un mapping verso un URI esterno
|
|
235
|
+
OPTIONAL { ?concept crm:P127_has_broader_term ?parent . }
|
|
265
236
|
BIND(
|
|
266
237
|
IRI(CONCAT("${rootIRI}", REPLACE(STR(?concept), "^.*[/#]", "")))
|
|
267
238
|
AS ?mappedConcept
|
|
268
239
|
)
|
|
269
|
-
|
|
270
240
|
}
|
|
271
|
-
ORDER BY ?
|
|
272
|
-
|
|
241
|
+
ORDER BY ?concept`
|
|
273
242
|
axios.post(fusekiUrl, `query=${encodeURIComponent(query)}`, {
|
|
274
243
|
headers: {
|
|
275
|
-
'Accept': `
|
|
244
|
+
'Accept': `application/sparql-results+json`,
|
|
276
245
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
277
|
-
}
|
|
278
|
-
responseType: 'text'
|
|
246
|
+
}
|
|
279
247
|
}).then(response => {
|
|
280
|
-
res.setHeader('Content-Type',
|
|
248
|
+
res.setHeader('Content-Type', 'text/turtle');
|
|
281
249
|
res.header('Access-Control-Allow-Origin', '*');
|
|
250
|
+
const bindings = response.data.results.bindings;
|
|
282
251
|
const client_uuid = crypto.randomUUID();
|
|
283
252
|
const table = 'vocabulary-cache'
|
|
253
|
+
let data_turtle = `PREFIX base: <http://www.ics.forth.gr/isl/CRMinf/>
|
|
254
|
+
PREFIX cpm: <http://ontome.net/ns/cpm/>
|
|
255
|
+
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
|
|
256
|
+
PREFIX crmsci: <http://www.cidoc-crm.org/extensions/crmsci/>
|
|
257
|
+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
|
258
|
+
PREFIX pref: <http://diagnostica/>
|
|
259
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
260
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
261
|
+
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
|
|
262
|
+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
263
|
+
`
|
|
264
|
+
for(let i=0; i<bindings.length; i++){
|
|
265
|
+
let item = bindings[i]
|
|
266
|
+
data_turtle += `
|
|
267
|
+
<${item.concept.value}>
|
|
268
|
+
rdf:type owl:Class;
|
|
269
|
+
rdfs:subClassOf <${item.parent.value}>;
|
|
270
|
+
skos:prefLabel "${item.label.value}"@${item.label["xml:lang"]} .
|
|
271
|
+
`
|
|
272
|
+
}
|
|
273
|
+
|
|
284
274
|
EditLocks.lockWithRetry(table, key, client_uuid).then( async (success) =>{
|
|
285
275
|
try{
|
|
286
276
|
if(success){
|
|
287
|
-
CacheVocabularies.set(key,
|
|
277
|
+
CacheVocabularies.set(key, data_turtle); // salva come stringa
|
|
288
278
|
await EditLocks.delete(table, key, client_uuid)
|
|
289
279
|
}
|
|
290
280
|
}catch(ex){
|
|
291
281
|
console.log(ex)
|
|
292
282
|
}
|
|
293
|
-
res.send(
|
|
283
|
+
res.send(data_turtle);
|
|
294
284
|
}).catch((e)=>{
|
|
295
285
|
console.log(e)
|
|
296
286
|
res.send(response.data);
|
|
297
287
|
})
|
|
298
288
|
}).catch(err => {
|
|
289
|
+
console.log(err)
|
|
299
290
|
res.status(500).json({
|
|
300
291
|
success: false,
|
|
301
292
|
data: null,
|
|
302
293
|
message: `Error: ${err}`
|
|
303
294
|
});
|
|
304
295
|
});
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
296
|
+
}
|
|
308
297
|
})
|
|
309
298
|
//---------------------------------------------------------------
|
|
310
299
|
|