Open sylvainlb opened 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.
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
.
Then I'm definitely experiencing a bug =)
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
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.
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 afetchContext
method returning a promise do the job?