rdflib.js icon indicating copy to clipboard operation
rdflib.js copied to clipboard

add jsonld capabilities

Open chrysn opened this issue 11 years ago • 6 comments
trafficstars

this only works if the jsonld.js library[1] is included. no dedicated parser is implemented, the work is delegated to that library, and a file type handler takes care of converting jsonld.js' node format into rdflib terms.

current caveats are:

  • jsonld.js brings has to launch xmlhttprequests by itself
  • there is content type handling code which i failed to trigger (see FIXME comment)
  • i didn't do test cases that involve the why part of statements, and my literals tests were few too (barely enough to see datatypes are terms but languages aren't)
  • accept priorities were set arbitrarily
  • no tests are implemented
  • the dependency on jsonld.js is not declared, and no tests were done without the library present.
  • when using the widespread crossSiteProxyTemplate http://data.fm/proxy?uri={uri}, be aware that json-ld does not seem to work with it.

[1] https://github.com/digitalbazaar/jsonld.js

chrysn avatar Jun 23 '14 17:06 chrysn

(mostly note to self:) when this gets applied together with content-location tracking, those additions will have to be added here as well (compare https://github.com/chrysn/rdflib.js/commit/7f484cd6fc62ef134010ab6b393d3269fb9016b4).

chrysn avatar Jun 26 '14 08:06 chrysn

I haven't looked at the code in detail but at first blush "jsonld.js brings has to launch xmlhttprequests by itself" is a problem. A parser has to be callable from web.js (or anywhere else) given a string to parse and a base URI and a quad store to put the data in. The XHR are kept track of an logged by web.js separately. Is it not possible to extract the core json-ld parser?

timbl avatar Nov 30 '14 23:11 timbl

Now I have looked at the code it looks as though the parser (.toRDF) in jsonld.js should be extractable, or usable without having to use the XHR bits. One could add a separate clone of it to target a rdflib.js quad store. It won't need the first/rest generation stuff for lists, but will be able to just make a list directly as a first object.

timbl avatar Dec 01 '14 00:12 timbl

i think that a jsonld module needs to to xmlhttprequests by design: the @context needs to be resolved before triples can be generated. things would be different if the context were an rdf document by itself, the yes, i'd expect the jsonld module to be integrated deeper and to use rdflib facilities. if some more control is needed (eg. to make the xhrs mockable), a documentLoader can be passed into .toRDF and will then be used to fulfill the requests.

as for the second comment (on quad store, first/rest generation), i don't understand what you are suggesting.

for the time being, i've rebased the otherwise unmodified pull request onto current master. this might solve issue #59. one further change was necessary:

i've noticed that the jsonld library is already used in rdflib these days, but in completely different parts (only available in node.js, and only for conversion to jsonld). to have those modes co-exist peacefully, i'd have to dig deeper into how to get a module available both from inside node.js and in the browser. (the var jsonld = require('jsonld'); made the jsonld module as loaded in the browser unavailable, i renamed it to avoid the clash).

chrysn avatar Apr 22 '15 06:04 chrysn

Any news regarding this PR ?

akuckartz avatar May 31 '15 07:05 akuckartz

Looks like this PR is outdated and can be closed given rdflib now has jsonld capabilities? https://github.com/linkeddata/rdflib.js/issues/59 has been closed

https://linkeddata.github.io/rdflib.js/doc/globals.html#jsonldparser https://github.com/linkeddata/rdflib.js/blob/master/src/jsonldparser.js

josephguillaume avatar Aug 09 '20 06:08 josephguillaume