Skip to content
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
demo Improve demo visualization of sets and lists Apr 27, 2017
lib
src/parsers Crudely fix handling of PNames as objects in TriG Jul 11, 2016
test Merge branch 'master' into support-multiple-formats Jul 23, 2016
tools
.gitignore Move parser code built by peg into lib and add to repository Jul 15, 2015
.npmignore Tweak .npmignore Jan 2, 2018
LICENSE.md
README.md
package.json

README.md

LDTR

A Linked Data Transcriber.



Intro

LDTR turns various representations of RDF into JSON-LD.

This is done by transcribing the syntax verbatim into a valid JSON-LD structure that represents the same RDF. Only use output from this tool directly when input is strictly under your control. In any other case, you need to pass the result through a JSON-LD processor (such as jsonld.js) in order to to have control over the shapes and terms of the results.

RDF is about meaning, not structure. Of course, meaning is always – indirectly but intrinsically – conveyed by structure. And if the structure is yours to begin with, you can leverage its shape directly for speed and convenience. As such, the practise of using JSON-LD as plain JSON is a bit like using C. Very effective and close to the metal, but rather dangerous if you don't know what you're doing.

To a certain point, this tool can be used as a teaching aid, for showing the isomorphisms of different RDF serializations. Note that prefix mechanisms (QNames/CURIEs/PNames) are basically only useful in RDF syntaxes for authoring. They are not intended to be consumed directly, syntactically, from the source. Thus, by producing a JSON-LD compliant semi-compact transcript like LDTR does, consumers who are unaware of what the tokens really mean (in RDF) may be misled to consider them fixed and atomic, instead of the locally defined shorthand forms they really are. This is why this form can only be trusted when you are in control of the source data.

Install

$ npm install ldtr

Command Line

$ ldtr RDF_FILE_OR_URL

Or:

$ cat TURTLE_FILE | ldtr

Supported Formats

The TriG parser is generated from a grammar file (based on the TriG W3C EBNF Grammar) using PEG.js.

Code

The API of this library isn't finalized yet. It strives to provide set of simple and independent modules, which should be usable both from the browser and on the server (e.g NodeJS).

For text-based formats, the input is expected to be a regular string. For XML- and HTML-based formats, the input should be a DOM Document. (Any W3C XML DOM Level 2 Core compliant DOMParser and XMLSerializer will do. For Node and CLI usage, LDTR uses xmldom.)

Parsing TriG:

var trigParser = require('ldtr/lib/trig/parser');
var jsonld = trigParser.parse('<a> :b "c" .');

Parsing RDFa:

var rdfaParser = require('ldtr/lib/rdfa/parser');
var doc = new DOMParser().parseFromString(xmlStr, 'text/html');
var jsonld = rdfaParser.parse(doc, baseUri, {compact: true});

Parsing RDF/XML:

var rdfxmlParser = require('ldtr/lib/rdfxml/parser');
var doc = new DOMParser().parseFromString(rdfStr, 'text/xml');
var jsonld = rdfxmlParser.parse(doc);
You can’t perform that action at this time.