ruby-rdf/json-ld

Add support for matching on @id when framing

gkellogg opened this issue · 5 comments

Match on other values as well.

From @abrisse

@dave : I was talking about the ruby gem json-ld:

frame = JSON.parse %({
  "@id": "http://www.myresource/uuid"
})

JSON::LD::API.frame(input, frame) returns the same structure

First example from @abrisse:

<?xml version='1.0' encoding='utf-8' ?>
<rdf:RDF xmlns:ns0='http://www.myresource.com/ontology/1.0#' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'>
  <rdf:Description rdf:about='http://www.myresource/uuid'>
    <ns0:talksAbout>
      <rdf:Description rdf:about='http://rdf.freebase.com/ns/m.018w8'>
        <rdfs:label xml:lang='en'>Basketball</rdfs:label>
      </rdf:Description>
    </ns0:talksAbout>
  </rdf:Description>
</rdf:RDF>

Basically when I use a standard serializer like the jsonld gem in Ruby to serialize it in JSON-LD I obtain (reproducible on http://rdf.greggkellogg.net/distiller)

{
  "@context": {
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
  },
  "@graph": [
    {
      "@id": "http://rdf.freebase.com/ns/m.018w8",
      "rdfs:label": [
        {
          "@value": "Basketball",
          "@language": "en"
        }
      ]
    },
    {
      "@id": "http://www.myresource/uuid",
      "http://www.myresource.com/ontology/1.0#talksAbout": [
        {
          "@id": "http://rdf.freebase.com/ns/m.018w8"
        }
      ]
    }
  ]
}

But I would like to obtain:

{
  "@context": {
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
  },
  "@id": "http://www.myresource/uuid",
  "http://www.myresource.com/ontology/1.0#talksAbout": [
      {
         "@id": "http://rdf.freebase.com/ns/m.018w8",
         "rdfs:label": [
           {
             "@value": "Basketball",
             "@language": "en"
           }
         ]
     }
  ]
}

Looks like the algorithm is operating property, which leads to an empty frame. From email thread:

Dave, I do have the support for supporting value matching on @id, but the reason this doesn’t work for me is that when the frame is expanded, it returns an empty array, rather than one containing on object with the expanded @id. If you take the frame from the playground link and expand it, you’ll get the same thing. Yet, when used for framing, your processor seems to act as if the frame is not empty.

My algorithm works by expanding both input and frame, and using that the frame the output, which is re-compacted using the context from the frame. Yours seems to work differently. The spec algorithm says it uses both expanded input and expanded frame, so yours looks like it doesn’t end up using the expanded frame.

From the expansion algorithm step 12.2: "Otherwise, if result is a JSON object whose only key is @id, set result to null”. This would seem to apply here, and result in a null frame, leading to an empty array result.

If I add “talksAbout”: {} to the frame, my processor works as expected.