-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added transform fro skolem-iris
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
./bin/rdf-ext-cli.js \ | ||
--pretty \ | ||
--transform-skolem-iris http://example.com/.well-known/genid/ \ | ||
--output-prefix houseplace=https://housemd.rdf-ext.org/place/ \ | ||
--output-prefix schema=http://schema.org/ \ | ||
https://housemd.rdf-ext.org/place/221b-baker-street |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { randomUUID } from 'node:crypto' | ||
import rdf from 'rdf-ext' | ||
import { Transform } from 'readable-stream' | ||
|
||
function transformSkolemIris (baseIri) { | ||
const nodeMap = rdf.termMap() | ||
|
||
const mapTerm = term => { | ||
if (term.termType === 'BlankNode') { | ||
if (!nodeMap.has(term)) { | ||
nodeMap.set(term, rdf.namedNode(`${baseIri}${randomUUID().split('-').join('')}`)) | ||
} | ||
|
||
return nodeMap.get(term) | ||
} | ||
|
||
return term | ||
} | ||
|
||
const mapQuad = quad => { | ||
return rdf.quad( | ||
mapTerm(quad.subject), | ||
mapTerm(quad.predicate), | ||
mapTerm(quad.object), | ||
mapTerm(quad.graph) | ||
) | ||
} | ||
|
||
return new Transform({ | ||
objectMode: true, | ||
transform: (quad, encoding, callback) => { | ||
callback(null, mapQuad(quad)) | ||
} | ||
}) | ||
} | ||
|
||
export default transformSkolemIris |