simplerdf / simplerdf

:ok_hand: The future simplest RDF library ever
http://npm.im/simplerdf
67 stars 8 forks source link

Add support for remote context #62

Open sylvainlb opened 8 years ago

sylvainlb commented 8 years ago

I'm creating this issue as a reminder, as I don't think it exists already. JSON-LD allows @context to be passed as a url. This should be possible in SimpleRDF. What's the best way? Would a fetchContext method returning a promise do the job?

csarven commented 8 years ago

What's happening in SimpleRDF right now is that when it encounters @context it fetches its value(s?) and maps it on the data. This is expensive, and should probably only happen as a last resort.

It'd be good to enable applications to pass in a cachedContext object as an option along with the request so that it is applied right away on the data instead of the @context that comes with the data. This has the benefit of cached context (see also http://manu.sporny.org/2016/json-ld-context-caching/ ) and as a side-effect allowing the application to override the context. It could work something like this:

var options = {
  cachedContext: {
    "@id": "http://example.org/foo.jsonld",
    context: { ... }
  }
}
SimpleRDF(..., options).get()

If the @context value in the data equals options.cachedContext["@id"], it can apply options.cachedContext.context.

To simplify all this, since SimpleRDF has context as its first parameter, can we update how that's handled so that a context URI in there is compared with the context in the retrieved data? Perhaps this is already possible but I'm not sure how to use that at the moment.

bergos commented 8 years ago

At the moment there is no support to fetch a remote context. If it does something, that it's a bug ;-)

Caching: We have already a Context class. That class can be also used in the constructor.

Proposal: Fetching a remote resource requires an async call. A Promise should be used. I would like to avoid polluting the API with async calls. A plugin could be implemented (may be added to the default package), which has the same interface like the constructor, but returns the SimpleRDF object via Promise.

csarven commented 8 years ago

Then I'm definitely experiencing a bug =)

csarven commented 7 years ago

It also seems to fall apart when offline i.e., can't fetch context. @context need not be cached necessarily. Just treat it as prefixes to have the absolute IRI

elf-pavlik commented 7 years ago

Just treat it as prefixes to have the absolute IRI

JSON-LD context may or may not include prefixes map and terms map, still if one doesn't have context denoted by particular IRI available one can NOT make any assumptions about prefixes it may or may not define.