This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from inrupt/comunica-problem
Attempt at using Comunica
- Loading branch information
Showing
15 changed files
with
1,776 additions
and
56 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,11 +1,50 @@ | ||
// import { newEngine } from '@comunica/actor-init-sparql' | ||
import rdf from 'rdf-ext' | ||
import Debug from 'debug' | ||
import { newEngine } from '@comunica/actor-init-sparql-rdfjs' | ||
import { Store } from 'n3' | ||
const debug = Debug('apply-query') | ||
|
||
// const myEngine = newEngine(); | ||
export async function applyQuery (store: any, sparqlQuery: string) { | ||
// const engine = newEngine() | ||
// const result = await engine.query(sparqlQuery, { | ||
function removeLeadingQuestionMark (str: string) { | ||
return str.substring(1) | ||
} | ||
|
||
// }) | ||
// const parsedQuery = parser.parse(sparqlQuery) | ||
// TODO: implement | ||
export async function applyQuery (dataset: any, sparqlQuery: string): Promise<string> { | ||
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(), | ||
value: obj[key].value | ||
} | ||
} | ||
bindings.push(binding) | ||
}) | ||
}) | ||
return JSON.stringify({ | ||
head: { | ||
vars: result.variables.map(removeLeadingQuestionMark) | ||
}, | ||
results: { | ||
ordered: false, | ||
distinct: false, | ||
bindings | ||
} | ||
}) | ||
} |
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
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 |
---|---|---|
@@ -1,5 +1 @@ | ||
PREFIX foaf: <http://xmlns.com/foaf/0.1/> | ||
SELECT ?name | ||
WHERE { | ||
?person foaf:name ?name . | ||
} | ||
SELECT ?name { ?person <http://xmlns.com/foaf/0.1/name> ?name. ?person ?z ?name } LIMIT 100 |
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
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