Last active
January 25, 2023 14:48
-
-
Save argahsuknesib/852bafc5d90c7a2696a62e4ad283a1b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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