Last active
November 16, 2022 10:41
-
-
Save phochste/ef249cccffbcb6583782526f0fe65b57 to your computer and use it in GitHub Desktop.
Example how to transform RDF from one serialisation to another
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
// npm install rdf-parse rdf-serialize stream-to-string streamify-string' | |
// node example.js | |
const rdfParser = require("rdf-parse").default; | |
const rdfSerializer = require("rdf-serialize").default; | |
const stringifyStream = require('stream-to-string'); | |
const streamifyString = require('streamify-string'); | |
doit(` | |
{ | |
"@context": "http://schema.org/", | |
"@type": "Person", | |
"name": "Jane Doe", | |
"jobTitle": { "@list": ["Professor", "Master" ] } , | |
"telephone": "(425) 123-4567", | |
"url": "http://www.janedoe.com" | |
} | |
`, | |
'application/ld+json', | |
'text/turtle' | |
); | |
async function doit(data,inType,outType) { | |
const inStream = streamifyString(data); | |
const quadStream = rdfParser.parse(inStream, { contentType: inType }); | |
const outStream = rdfSerializer.serialize(quadStream, { contentType: outType }); | |
console.log(await stringifyStream(outStream)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment