w3c / json-ld-syntax

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

Using @context on children of a mapped vocabulary #392

Closed PonteIneptique closed 2 years ago

PonteIneptique commented 2 years ago

Hello :) First of all, I am very very not used to JSON-LD @context, I have been on the receiving end of JSON-LD content more than on writing useful @context.

In the context of our API Specification, we are trying to figure out how to have the @language property under a dct:* property mapped to language while keeping language at the "root" level of the mapped vocabulary to dct:language.

As this is very confusing, here is an example:

{
  "dublincore": {
    "title": [
      {"language": "en", "value": "Hello"} // This language should be @language
    ],
    "language" : ["en"] // This language should be dct:language
  }
}

My current tries drove me to something like this

  "@context": {
    "dct": "http://purl.org/dc/terms/",
    "dts": "https://w3id.org/dts/api#",
    "language": "@language",
    "value": "@value",
    "dublincore": {
      "@id": "dts:dublincore",
      "@context": {
        "@vocab": "http://purl.org/dc/terms/",
        "language": "http://purl.org/dc/terms/language",
        "null": { // This obviously does not work
          "@context": {
            "language": "@language"
          }
        }
      }
    }
  }

I'd be most thankful if you could help us on this specific task.

If this is the wrong canal for such a question, please accept my apologies.

pchampin commented 2 years ago

I don't think there is an easy way to achieve that, unfortunately.

One way out would be to not use the same attribute name, e.g. use lang (as in HTML) as an alias to @language , and language for dct:language.

If using the same attribute is unavoidable, I would push the alias down to every property that needs it (example in playground), but that's induces quite some redundancy.

If you still want to alias language to @language at the top level, you need to override it in the scoped context of dublincore, and then override it again for every property expecting a langString (example in playground).

PonteIneptique commented 2 years ago

Thanks @pchampin, that's definitely what I thought. I guess we'll go for @lang in the main @context then :)