Add files via upload

This commit is contained in:
Dmitry 2025-03-12 18:08:19 +03:00 committed by GitHub
parent 65e70b92a7
commit dfa73c3f78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,39 @@
const QueryEngine = require('@comunica/query-sparql-file').QueryEngine;
const myEngine = new QueryEngine();
const bindingsStream = await myEngine.queryBindings(`
SELECT ?s ?p ?o WHERE {
?s ?p <http://dbpedia.org/resource/Belgium>.
?s ?p ?o
} LIMIT 100`, {
sources: ['http://fragments.dbpedia.org/2015/en'],
});
// Consume results as a stream (best performance)
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.
});
bindingsStream.on('error', (error) => {
console.error(error);
});
// Consume results as async iterable (easier)
for await (const binding of bindingsStream) {
console.log(binding.toString());
}
// Consume results as an array (easier)
const bindings = await bindingsStream.toArray();
console.log(bindings[0].get('s').value);
console.log(bindings[0].get('s').termType);