json-ld / json-ld.org

JSON for Linked Data's documentation and playground site
https://json-ld.org/
Other
858 stars 152 forks source link

Consider value as part of vocabulary-IRI #771

Closed weissjoh closed 2 years ago

weissjoh commented 2 years ago

I have the case that within a JSON document is included which contains an attribute with a string. This value is pointing to an item of an enumeration resp. a named individual. However, just the name and not the full IRI.

{
  "@context": {
    "enumtype": {
      "@context": { "@base": "http://myvocab.com/devices#" },
      "@type": "@id",
      "@id": "http://myvocab.com/ownership#belongsTo"
    }
  },
  "@id": "http://example.com/id-1",
  "enumtype": "notebook"
}

I do get back the following turtle:

<http://example.com/id-1> <http://myvocab.com/ownership#belongsTo> <http://myvocab.com/notebook> .

However, I am expecting the following result as turtle:

<http://example.com/id-1> <http://myvocab.com/ownership#belongsTo> <http://myvocab.com/devices#notebook> .

Interestingly the devices# from the @base definition is cut off. I am wondering if there is some tweak possible to get my expected result. Here is the link to JSON-LD Playground.

niklasl commented 2 years ago

Since enumtype is defined with @type: @id, its value is treated as a relative IRI, which is then resolved against the @base in the term-scoped context. To get what you want here, you need to express it like this:

{
  "@context": {
    "enumtype": {
      "@context": {
        "@vocab": "http://myvocab.com/devices#"
      },
      "@type": "@vocab",
      "@id": "http://myvocab.com/ownership#belongsTo"
    }
  },
  "@id": "http://example.com/id-1",
  "enumtype": "notebook"
}
weissjoh commented 2 years ago

@niklasl amazing. Thank you very much for your help. This actually solves the problem 👍