Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

N3 to JSON-LD

node v10.24.1
version: master
endpointsharetweet
const rdflib = require('rdflib'); // it will be `Error: Missing IRI for NamedNode` if uri is '' function turtle2jsonld( turtleString, uri = '', store = rdflib.graph()){ return new Promise(resolve=>{ rdflib.parse( turtleString, store, uri, "text/turtle", e => { if(e) { console.log("Parse Error! "); return resolve(e) } rdflib.serialize(null,store, uri,'application/ld+json',(e,s)=>{ if(e) { console.log("Serialize Error! "); return resolve(e) } return resolve(s) }) }) }) } const text = `@prefix : <#>. @prefix m: <>. @prefix ldp: <http://www.w3.org/ns/ldp#>. @prefix terms: <http://purl.org/dc/terms/>. @prefix XML: <http://www.w3.org/2001/XMLSchema#>. @prefix st: <http://www.w3.org/ns/posix/stat#>. @prefix tur: <http://www.w3.org/ns/iana/media-types/text/turtle#>. ` const resultJSONLD = await turtle2jsonld(text); console.log(resultJSONLD)
const text2 = `@prefix : <#>. @prefix m: <>. @prefix ldp: <http://www.w3.org/ns/ldp#>. @prefix terms: <http://purl.org/dc/terms/>. @prefix XML: <http://www.w3.org/2001/XMLSchema#>. @prefix st: <http://www.w3.org/ns/posix/stat#>. @prefix tur: <http://www.w3.org/ns/iana/media-types/text/turtle#>. m: a ldp:BasicContainer, ldp:Container; terms:modified "2019-12-24T03:53:21Z"^^XML:dateTime; ldp:contains <%2524%253A%252FStoryList>, <%2524%253A%252FStoryList.metadata>, <Draft%2520of%2520'New%2520Tiddler'%2520by%2520https%253A%252F%252Flinonetwo.solid.authing.cn%252Fprofile%252Fcard%2523me.metadata>, m:Test, <Test.metadata>, m:Test123, <Test123.metadata>; st:mtime 1577159601.427; st:size 4096. <%2524%253A%252FStoryList> a ldp:Resource; terms:modified "2019-12-24T03:45:21Z"^^XML:dateTime; st:mtime 1577159121.851; st:size 0. <%2524%253A%252FStoryList.metadata> a tur:Resource, ldp:Resource; terms:modified "2019-12-24T03:53:21Z"^^XML:dateTime; st:mtime 1577159601.427; st:size 553. <Draft%2520of%2520'New%2520Tiddler'%2520by%2520https%253A%252F%252Flinonetwo.solid.authing.cn%252Fprofile%252Fcard%2523me.metadata> a tur:Resource, ldp:Resource; terms:modified "2019-12-23T16:33:02Z"^^XML:dateTime; st:mtime 1577118782.611; st:size 974. m:Test a ldp:Resource; terms:modified "2019-12-23T16:24:47Z"^^XML:dateTime; st:mtime 1577118287.375; st:size 3. <Test.metadata> a tur:Resource, ldp:Resource; terms:modified "2019-12-23T16:24:46Z"^^XML:dateTime; st:mtime 1577118286.731; st:size 786. m:Test123 a ldp:Resource; terms:modified "2019-12-23T16:33:09Z"^^XML:dateTime; st:mtime 1577118789.463; st:size 7. <Test123.metadata> a tur:Resource, ldp:Resource; terms:modified "2019-12-23T16:33:08Z"^^XML:dateTime; st:mtime 1577118788.643; st:size 792.` const resultJSONLD = await turtle2jsonld(text2, 'https://linonetwo.solid.authing.cn/public/tiddlywiki/main'); console.log(resultJSONLD)
Loading…

no comments

    sign in to comment