w3c / json-ld-syntax

JSON-LD 1.1 Specification
https://w3c.github.io/json-ld-syntax/
Other
112 stars 22 forks source link

@context as relative IRI #311

Closed hsolbrig closed 4 years ago

hsolbrig commented 4 years ago

The specification says that an @context can be an IRI reference, meaning that it can be an absolute or a relative IRI. Questions: 1) If relative, is it resolved against the document base? 2) Why doesn't this appear to work in the playground? (see: http://tinyurl.com/u6z4ot7 for one attempt)

gkellogg commented 4 years ago

It is relative to the document in which it is contained. It should work properly in jsonld.js, but in the embedded context of the playground, this may not be apparent.

hsolbrig commented 4 years ago

Is it document relative only, or can it be changed with '@base'?

gkellogg commented 4 years ago

There are tests for this, and I believe it does not consider @base.

gkellogg commented 4 years ago

5.2 of the Context Processing Algorithm makes this pretty clear:

Initialize context to the result of resolving context against the base IRI of the document containing the local context which is established

It's detailed enough, and I don't think we really need to burden the syntax document with this much detail.

ericprud commented 4 years ago

I tried some pretty trivial tests using the npm module to parse a JSON-LD doc which referenced another:

{ "@context": "http://localhost/tmp/npmz/jsonld-user/outer.jsonld",
  "outer": { "inner": "http://inner/" } }

which in turn referenced another:

{ "@context": {  "@version": 1.1,
    "outer": {
      "@id": "foo:outer",
      "@context": "http://localhost/tmp/npmz/jsonld-user/inner.jsonld"
    } } }

(both served as "application/ld+json") This worked as long as the URLs were absolute but not when I changed e.g. that 2nd to have an @context of either "inner.jsonld" or "/tmp/npmz/jsonld-user/inner.jsonld". Should this be covered by the tests?

gkellogg commented 4 years ago

I thought we had a test for this from 1.0, but I don't see one, so something like this is certainly necessary.

hsolbrig commented 4 years ago

5.2 of the Context Processing Algorithm makes this pretty clear:

Initialize context to the result of resolving context against the base IRI of the document containing the local context which is established

It's detailed enough, and I don't think we really need to burden the syntax document with this much detail.

While there is definitely detail that is irrelevant to JSON-LD end user, I don't see this question falling into that category. Where we are today, the syntax document appears be the document that json-ld users would go to to answer questions about how the language is used and interpreted. Less than ideal, I know, but requiring someone to have consumed all three specifications before being able to use JSON-LD in anger is asking an awful lot.

ericprud commented 4 years ago

I thought we had a test for this from 1.0, but I don't see one, so something like this is certainly necessary.

The above pull provides one which is the only test for:

  1. @context referenced @context
  2. @context with relative URLs

I created an analogous remote test but a PR on that will fail until it gets merged as it relies on https://w3c.github.io/json-ld-api/tests .

iherman commented 4 years ago

This issue was discussed in a meeting.