-
Notifications
You must be signed in to change notification settings - Fork 211
Description
I have had good success reading RDF/XML, Turtle and JSON-LD resources with rdflib, and doing in-memory SPQRQL-like queries on the graphs. However, I would like to explore using jsonld.js so that applications can use native JSON and sift.js instead of the rdflib IndexedFormulas and queries.
Unfortunately jsonld.js only parses application/nquads. But it has a means of registering other parsers. I tried to create a jsonld parser for RDF/XML using rdf-ext:
var rdf = require('rdf-ext')();
var rdfXmlParser = function(input, callback) {
var parser = new rdf.RdfXmlParser();
parser.parse(input, function doneParsing(dataset) {
callback(undefined, {'graph': dataset.toArray()});
});
}
jsonld.registerRDFParser('application/rdf+xml', rdfXmlParser);
jsonld.fromRDF(rs_xml.toString(), {}, function loadRDFXML(err, doc) {
...
But this doesn't work since the RDF dataset format expected by jsonld requires the triples to be URIs or primitive types, not the objects that are created by the rdf-ext parsers.
Are there any examples of RDF/XML, Turtle, and JSON-LD parsers for jsonld.js? If now, how would one go about creating them? Are there things that could be reused like rdflib, rdf-ext, rdfstore-js, or rdf-interfaces that would be useful starting points?
Or is there a better way to do what I'm trying to do - query RDF resources using JSON in JavaScript?
Thanks for the help.