w3c / json-ld-syntax

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

Expanded containers. #292

Closed davidlehn closed 4 years ago

davidlehn commented 4 years ago

I'm not sure where best to track post-1.1 features. Please move or label this as appropriate. This comes from IRC and gitter. https://gitter.im/json-ld/json-ld.org?at=5d852a8c2438b53a64e95467

The use case is wanting to perform compaction and have a uniform output data shape for easier processing. When using @language on some values, but not others, you can end up with a non-uniform output shape. Is there some trick with current features that would make a uniform compacted shape possible? Or is pre or post processing the preferred solution in such cases?

One solution would be to add @expand as a value for @container (potentially with other flags as well). When compacting, those values would always be expanded. (Would need to consider interaction with other features like language maps.)

Current input:

{
  "@context": {
    "p": {
      "@id": "ex:p"
    }
  },
  "p": [
    {
      "@value": "p-aa",
      "@language": "aa"
    },
    "p-bb"
  ]
}

Current compacted output (using input context) can be difficult to easily process:

{
  "@context": {
    "p": {
      "@id": "ex:p"
    }
  },
  "p": [
    {
      "@language": "aa",
      "@value": "p-aa"
    },
    "p-bb"
  ]
}

Possible container feature input:

{
  "@context": {
    "p": {
      "@id": "ex:p",
      "@container": "@expand"
    }
  },
  "p": [
    {
      "@value": "p-aa",
      "@language": "aa"
    },
    "p-bb"
  ]
}

Possible compacted output (using input context):

{
  "@context": {
    "p": {
      "@id": "ex:p",
      "@container": "@expand"
    }
  },
  "p": [
    {
      "@language": "aa",
      "@value": "p-aa"
    },
    {
      "@value": "p-bb"
    }
  ]
}
gkellogg commented 4 years ago

Language maps might make a more consistent output. We also allow @type: @none, which has that affect.

gkellogg commented 4 years ago

This seems to be a duplicate of https://github.com/w3c/json-ld-api/issues/33, which was merged in https://github.com/w3c/json-ld-api/pull/63.

davidlehn commented 4 years ago

So many exciting new 1.1 features I'm losing track! Original question was to do this without language maps. It does look like that "@type": "@none" feature works (in the distiller). Not yet supported in jsonld.js though.

Compaction context:

{
  "@context": {
    "@version": 1.1,
    "p": {
      "@id": "ex:p",
      "@type": "@none"
    }
  }
}

Output:

{
  "@context": {
    "@version": 1.1,
    "p": {
      "@id": "ex:p",
      "@type": "@none"
    }
  },
  "p": [
    {
      "@value": "p-aa",
      "@language": "aa"
    },
    {
      "@value": "p-bb"
    }
  ]
}

@andygreenegrass Does that look like what you were asking for?

I think this issue can be closed.