Created
April 15, 2021 10:27
-
-
Save BruJu/7384eeb1f14e4b2bb5bca20c7e1906da to your computer and use it in GitHub Desktop.
Unblanknode
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
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