Skip to content

Instantly share code, notes, and snippets.

@argahsuknesib
Last active January 25, 2023 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save argahsuknesib/852bafc5d90c7a2696a62e4ad283a1b7 to your computer and use it in GitHub Desktop.
Save argahsuknesib/852bafc5d90c7a2696a62e4ad283a1b7 to your computer and use it in GitHub Desktop.
async execute(container: QuadContainer) {
const inferredTripleStore = new N3.Store();
const store = new N3.Store();
let parser = new N3.Parser({ format: 'Notation3', blankNodePrefix: 'bnode' });
const QueryEngine = require('@comunica/query-sparql').QueryEngine;
const comunicaEngine = new QueryEngine();
for (let elem of container.elements) {
store.addQuad(elem);
}
for (let elem of this.staticData) {
store.addQuad(elem);
}
const storeToString: string = store.getQuads().map((q: Quad) => '<' + q.subject.value + '> <' + q.predicate.value + '> <' + q.object.value + '> .').join('\n');
const Module =
await SwiplEye({
print: (str: string) => {
try {
if (str !== null || str !== undefined || str !== '' || str !== '\r\n' || str !== '\n') {
if (str.length > 1) {
parser.parse(str, (_error: any, quad: any, prefixes: any) => {
if (quad !== null) {
inferredTripleStore.addQuad(quad);
// generate a template for promise
let promise = new Promise((resolve, reject) => {
if (inferredTripleStore.size > 0) {
resolve(inferredTripleStore);
}
else {
reject("Error");
}
});
promise.then(
async (value) => {
console.log("Inferred triple store is: ", value);
return await comunicaEngine.queryBindings(this.query, { sources: [inferredTripleStore] });
}
).catch((error) => {
console.log("Error is: ", error);
});
}
else {
console.log("# That's all, folks!", prefixes);
}
})
}
};
}
catch (e) {
console.log("Error is: " + e);
}
parser = new N3.Parser({ format: 'Notation3', blankNodePrefix: '' });
}, arguments: ['-q', '--pass-all']
});
runQuery(Module, storeToString, this.rules);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment