w3c / json-ld-framing

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

Use a property several time when framing #122

Closed Murloc6 closed 1 year ago

Murloc6 commented 2 years ago

We are trying to round trip json-ld with framing.

Our input json-ld document is:

{
  "@context": {
    "td": "http://my-url#",
    "name": "td:name",
    "properties": {
      "@id": "td:property",
      "@container": "@index",
      "@index": "name"
    }
  },
  "@id": "urn:toto",
  "@type": "td:Thing",
  "properties": {
    "myprop": {
      "td:prop1": "123",
      "name": "myprop"
    }
  }
}

We obtain the following triples:

<urn:toto> <http://my-url#property> _:b0 .
<urn:toto> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://my-url#Thing> .
_:b0 <http://my-url#name> "myprop" .
_:b0 <http://my-url#prop1> "123" .

On this way, everything is fine since the property "name" is used to generate a single triple. When we want to frame these data to obtain the exact same json-ld document, the "name" property disappeared since it has been used as an "@index".

In other words, we obtain this:

  "properties": {
    "myprop": {
      "td:prop1": "123"
    }
  }

And we would like to have this:

"properties": {
    "myprop": {
      "td:prop1": "123",
      "name": "myprop"
    }
  }

Do you know a way to define the frame (or the context) to use the property twice (as "@index" and as an explicit key-value)?

playground example

gkellogg commented 2 years ago

I think you're trying to use Property Indexing to represent this information, but you're expecting the result to contain duplicate results.

The idea of Property Indexing is that you can have multiple values (node objects, in this case) that are indexed by a common property, perhaps having different values. The example in the spec has a property for "athletes" which is indexed on the jobTitle of each athlete. So, there is a top level object with an "athletes" property which, if not for indexing, would have an array value with entries for each athlete, containing their own jobTitle. Specifying this as a property index map uses that value for the index, instead of as a property of the node object.

For your example, you have multiple values of "property", which is indexed by "name", so having the name as the index value and as a property of the node object would be redundant, as we've already said to use this value as the index. There is no way to express in a frame that you want repeat that property value inside the node object.