rubensworks / rdf-dereference.js

Dereference any URL for its RDF contents
MIT License
33 stars 4 forks source link

Question: dereference JSON-LD document without dereferencing its contexts? #48

Closed sdevalk closed 11 months ago

sdevalk commented 11 months ago

I use this package - with great pleasure - to dereference IRIs of JSON-LD documents. However, I find the dereferencing to be a bit slow, e.g. when using this IRI.

I get the impression that this package not only dereferences the actual IRIs, but also the IRIs that are mentioned in the @contexts of the JSON-LD documents. Is that correct? Or when looking at the sample IRI: does it request the @context IRIs, http://iiif.io/api/presentation/2/context.json and http://iiif.io/api/image/2/context.json? If so, is it possible to disable this?

rubensworks commented 11 months ago

Following the JSON-LD document semantics, all @context values do indeed have to be dereferenced when parsing a document. There's no way to disable this, as this could cause differences in parsing, and thereby lead to wrong parsed data.

What is possible on the other hand, is caching or prefetching these contexts using a custom IDocumentLoader.

sdevalk commented 11 months ago

Thanks for the clear explanation, @rubensworks - that makes sense.

Caching or prefetching the contexts sounds perfect. Do you know how I can use a customer document loader?

I use this package in a module of my own that mostly dereferences JSON-LD documents, and occasionally documents in other RDF serializations. Is there a way to pass a custom loader for JSON-LD documents that is ignored for e.g. Turtle or N-Triples documents?

rubensworks commented 11 months ago

Caching or prefetching the contexts sounds perfect. Do you know how I can use a customer document loader?

@sdevalk I should probably document this at some point, but something like the following should work (untested):

dereference('http://...', { '@comunica/actor-rdf-parse-jsonld:documentLoader': new MyDocumentLoader() });

Where MyDocumentLoader implements https://github.com/rubensworks/jsonld-context-parser.js/blob/master/lib/IDocumentLoader.ts

sdevalk commented 11 months ago

@rubensworks Thanks for the pointer! 👍🏻