-
Notifications
You must be signed in to change notification settings - Fork 0
/
query-custom.js
35 lines (28 loc) · 1.02 KB
/
query-custom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const QueryEngine = require('@comunica/query-sparql').QueryEngine;
const myEngine = new QueryEngine();
// see https://www.decodingweb.dev/await-is-only-valid-in-async-functions-node
(async () => {
const bindingsStream = await myEngine.queryBindings(`
SELECT ?s ?p ?o WHERE {
?s ?p <http://dbpedia.org/resource/Belgium>.
?s ?p ?o
} LIMIT 100`, {
sources: ['https://fragments.dbpedia.org/2015/en'],
});
bindingsStream.on('data', (binding) => {
console.log(binding.toString()); // Quick way to print bindings for testing
console.log(binding.has('s')); // Will be true
// Obtaining values
console.log(binding.get('s').value);
console.log(binding.get('s').termType);
console.log(binding.get('p').value);
console.log(binding.get('o').value);
});
bindingsStream.on('end', () => {
// The data-listener will not be called anymore once we get here.
console.log("Query execution has ended !")
});
bindingsStream.on('error', (error) => {
console.error(error);
});
})()