-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bd6485
commit 0da727b
Showing
6 changed files
with
534 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const ProxyHandlerStatic = require('@comunica/actor-http-proxy').ProxyHandlerStatic; | ||
const { KeysInitQuery } = require('@comunica/context-entries'); | ||
const { ActionContext } = require('@comunica/core'); | ||
const RdfStore = require('rdf-stores').RdfStore; | ||
const RdfTestSuite = require('rdf-test-suite'); | ||
|
||
module.exports = function(engine) { | ||
return { | ||
parse(query, options) { | ||
return engine.actorInitQuery.mediatorQueryProcess.bus.actors[0].parse(query, new ActionContext({ [KeysInitQuery.baseIRI.name]: options.baseIRI })); | ||
}, | ||
query(data, queryString, options) { | ||
return this.queryLdf([{ type: 'rdfjs', value: source(data) }], null, queryString, options); | ||
}, | ||
async queryLdf(sources, proxyUrl, queryString, options) { | ||
sources = sources.map((source) => { | ||
if (source.type === 'rdfjsSource') { | ||
source.type = 'rdfjs'; | ||
} | ||
if (source.type === 'hdtFile') { | ||
source.type = 'hdt'; | ||
} | ||
return source; | ||
}); | ||
const result = await engine.query(queryString, { | ||
baseIRI: options.baseIRI, | ||
sources, | ||
httpProxyHandler: proxyUrl ? new ProxyHandlerStatic(proxyUrl) : null, | ||
httpRetryOnServerError: true, | ||
httpRetryCount: 3, | ||
httpRetryDelay: 10, | ||
}); | ||
if (result.resultType === 'boolean') { | ||
return new RdfTestSuite.QueryResultBoolean(await result.execute()); | ||
} | ||
if (result.resultType === 'quads') { | ||
return new RdfTestSuite.QueryResultQuads(await require('arrayify-stream').default(await result.execute())); | ||
} | ||
if (result.resultType === 'bindings') { | ||
return new RdfTestSuite.QueryResultBindings( | ||
(await result.metadata()).variables.map(variable => `?${variable.value}`), | ||
(await require('arrayify-stream').default(await result.execute())) | ||
.map(binding => Object.fromEntries([ ...binding ] | ||
.map(([ key, value ]) => [ `?${key.value}`, value ]))), | ||
); | ||
} | ||
throw new Error(`Invalid query result type: ${result.resultType}`); | ||
}, | ||
async update(data, queryString, options) { | ||
const store = await source(data); | ||
const result = await engine.query(queryString, { | ||
baseIRI: options.baseIRI, | ||
sources: [{ type: 'rdfjs', value: store }], | ||
destination: store, | ||
}); | ||
await result.execute(); | ||
return store.getQuads(); | ||
}, | ||
}; | ||
}; | ||
|
||
function source(data) { | ||
const store = RdfStore.createDefault(); | ||
for (quad of data) { | ||
store.addQuad(quad); | ||
} | ||
return store; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const QueryEngine = require('@comunica/query-sparql-hdt').QueryEngine; | ||
module.exports = require('./sparql-engine-base.js')(new QueryEngine()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.