w3c / json-ld-framing

JSON-LD 1.1 Framing Specification
https://w3c.github.io/json-ld-framing/
Other
25 stars 20 forks source link

Provide an option for all terms to get a default "@container" #31

Closed michaelcpuckett closed 5 years ago

michaelcpuckett commented 5 years ago

I would like to have all my relational data come back as arrays of IDs.

Right now I have to add the following to @context for each term:

      "foo": {
        "@container": "@set",
        "@type": "@id"
      },

I propose a processor option (similar to embed) that would allow a default container.

iherman commented 5 years ago

This issue was discussed in a meeting.

michaelcpuckett commented 5 years ago

Thanks @iherman for reviewing this.

For my specific case, I want to model my data based on schema.org. I want to keep a generic, reusable frame and have the schema.org @vocab do the heavy lifting of mapping the relationships. Unfortunately I must define every schema.org term I might use in the @context. If these could all be set to a default, I would not need to have complete knowledge of the vocabulary I'm using.

jsonld.frame(json, {
  "@context": {
    "@vocab": "http://schema.org/",
    "agent": {
      "@container": "@set",
      "@type": "@id"
    },
    "participant": {
      "@container": "@set",
      "@type": "@id"
    },
    "recipient": {
      "@container": "@set",
      "@type": "@id"
    },
    "author": {
      "@container": "@set",
      "@type": "@id"
    },
    ...
  },
})

If there is a simpler way to achieve this, please let me know.

azaroth42 commented 5 years ago

Thanks @michaelcpuckett ! There isn't an easier way to do it I'm afraid, as the situation where every term in a vocabulary should always be @container: @set is vanishingly small. It would mean that every relationship was aways one to many or many to many, and never one to one or one to many. (It's also a syntax issue for compaction via setting a context, rather than a framing issue per se, but that's not a big deal)

My understanding of the intent of @vocab is to provide a default mapping from JSON to RDF, rather than a default mapping from RDF into a particular JSON structure. We have heard from several parties that the schema.org approach of just throwing @vocab in there and letting the application sort it out is often insufficient, and it seems like you're in the same boat.