Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function test () {
// This can be any RDFJS source
// In this example, we wrap an N3Store
const store = new Store()
store.addQuad(DataFactory.quad(
DataFactory.namedNode('a'), DataFactory.namedNode('b'), DataFactory.namedNode('http://dbpedia.org/resource/Belgium')))
store.addQuad(DataFactory.quad(
DataFactory.namedNode('a'), DataFactory.namedNode('b'), DataFactory.namedNode('http://dbpedia.org/resource/Ghent')))
// Create our engine, and query it.
// If you intend to query multiple times, be sure to cache your engine for optimal performance.
const myEngine = newEngine()
const result: any = await myEngine.query('SELECT * { ?s ?p . ?s ?p ?o } LIMIT 100',
{ sources: [ { type: 'rdfjsSource', value: store } ] })
result.bindingsStream.on('data', (data: any) => {
console.log(data)
})
}
void test()
async function applyQuery (dataset: any, sparqlQuery: string): Promise {
const store = new Store()
dataset.forEach((quad: any) => {
debug('quad', quad.toString())
store.addQuad(quad)
})
const myEngine = newEngine()
const result: any = await myEngine.query(sparqlQuery,
{ sources: [ { type: 'rdfjsSource', value: store } ] })
// const sparqlResult = await myEngine.resultToString(result, 'application/json')
// debug(sparqlResult)
const bindings = await new Promise((resolve) => {
const bindings: any = []
result.bindingsStream.on('end', () => {
resolve(bindings)
})
result.bindingsStream.on('data', (data: any) => {
const binding: any = {}
const obj = JSON.parse(JSON.stringify(data))
debug(obj)
for (const key in obj) {
binding[removeLeadingQuestionMark(key)] = {
type: obj[key].termType.toLowerCase(),
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
store = new n3_1.Store();
store.addQuad(n3_1.DataFactory.quad(n3_1.DataFactory.namedNode('a'), n3_1.DataFactory.namedNode('b'), n3_1.DataFactory.namedNode('http://dbpedia.org/resource/Belgium')));
store.addQuad(n3_1.DataFactory.quad(n3_1.DataFactory.namedNode('a'), n3_1.DataFactory.namedNode('b'), n3_1.DataFactory.namedNode('http://dbpedia.org/resource/Ghent')));
myEngine = actor_init_sparql_rdfjs_1.newEngine();
return [4 /*yield*/, myEngine.query('SELECT * { ?s ?p . ?s ?p ?o } LIMIT 100', { sources: [{ type: 'rdfjsSource', value: store }] })];
case 1:
result = _a.sent();
result.bindingsStream.on('data', function (data) {
console.log(data);
});
return [2 /*return*/];
}
});
});