@igea/oac_backend 1.0.13 → 1.0.14
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
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const router = express.Router();
|
|
3
|
+
const config = require('../config')
|
|
4
|
+
const configFuseki = config.fuseki || {
|
|
5
|
+
"protocol": "http",
|
|
6
|
+
"host": "127.0.0.1",
|
|
7
|
+
"port": "3030",
|
|
8
|
+
"dataset": "oac"
|
|
9
|
+
}
|
|
10
|
+
const fusekiUrl = `${configFuseki.protocol}://${configFuseki.host}:${configFuseki.port}/${configFuseki.dataset}/sparql`;
|
|
11
|
+
const axios = require('axios');
|
|
12
|
+
|
|
13
|
+
router.get('/count/entities', (req, res) => {
|
|
14
|
+
const query = `
|
|
15
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
16
|
+
PREFIX ex: <http://www.cidoc-crm.org/extensions/crmsci/>
|
|
17
|
+
|
|
18
|
+
SELECT ?type (COUNT(?entity) AS ?count)
|
|
19
|
+
WHERE {
|
|
20
|
+
?entity rdf:type ?type .
|
|
21
|
+
VALUES ?type { ex:S13_Sample ex:S5_Inference_Making }
|
|
22
|
+
}
|
|
23
|
+
GROUP BY ?type`
|
|
24
|
+
axios.post(fusekiUrl, `query=${encodeURIComponent(query)}`, {
|
|
25
|
+
headers: {
|
|
26
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
27
|
+
'Accept': 'application/sparql-results+json'
|
|
28
|
+
}
|
|
29
|
+
}).then(response => {
|
|
30
|
+
const bindings = response.data.results.bindings;
|
|
31
|
+
let results = []
|
|
32
|
+
bindings.forEach(result => {
|
|
33
|
+
results.push({
|
|
34
|
+
type: result.type.value,
|
|
35
|
+
count: parseInt(result.count.value)
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
res.json({
|
|
39
|
+
success: true,
|
|
40
|
+
data: results,
|
|
41
|
+
message: null
|
|
42
|
+
});
|
|
43
|
+
}).catch(err => {
|
|
44
|
+
res.status(500).json({
|
|
45
|
+
success: false,
|
|
46
|
+
data: null,
|
|
47
|
+
message: `Error: ${err}`
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
module.exports = router
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,8 @@ const jwtLib = jwtLibFactory({
|
|
|
10
10
|
excludePaths: [
|
|
11
11
|
`/${serviceName}/auth/authenticate`,
|
|
12
12
|
`/${serviceName}/auth/echo`,
|
|
13
|
-
`/${serviceName}/health
|
|
13
|
+
`/${serviceName}/health`,
|
|
14
|
+
`/${serviceName}/fuseki/count/entities`
|
|
14
15
|
],
|
|
15
16
|
signOptions: { expiresIn: '15m' }
|
|
16
17
|
});
|
|
@@ -50,6 +51,9 @@ getPort.default({
|
|
|
50
51
|
const usersRouter = require('./controllers/users.js')
|
|
51
52
|
app.use(`/${serviceName}/users`, usersRouter)
|
|
52
53
|
|
|
54
|
+
const fusekiRouter = require('./controllers/fuseki.js')
|
|
55
|
+
app.use(`/${serviceName}/fuseki`, fusekiRouter)
|
|
56
|
+
|
|
53
57
|
app.listen(port, async () => {
|
|
54
58
|
console.log(`${serviceName} listening on port ${port}`)
|
|
55
59
|
await register()
|