Skip to content

Instantly share code, notes, and snippets.

@BruJu
Created April 15, 2021 10:27
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 BruJu/7384eeb1f14e4b2bb5bca20c7e1906da to your computer and use it in GitHub Desktop.
Save BruJu/7384eeb1f14e4b2bb5bca20c7e1906da to your computer and use it in GitHub Desktop.
Unblanknode
const N3 = require('n3');
/**
* Return the description of the `term`.
*
* The description is:
* - the term itself if it is not a blank node
* - if it is a blank node, a list of every [predicate, object] for which
* there exists a (term, predicate, object) quad in the default graph of the
* store
*
* @param {N3.Store} store The store
* @param {*} term The term
* @returns An array with the informations about the term
*/
function readInfo(store, term) {
if (term.termType == "BlankNode") {
const quads = store.getQuads(term, null, null, N3.DataFactory.defaultGraph());
return quads.map(quad => [quad.predicate, readInfo(store, quad.object)]);
} else {
return term;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment