ruby-rdf / json-ld

Ruby JSON-LD reader/writer for RDF.rb
The Unlicense
232 stars 27 forks source link

Framing returns a blank @graph. #30

Closed workergnome closed 7 years ago

workergnome commented 8 years ago

When I try and frame a document, I'm getting a blank graph returned.


require 'linkeddata'

unframed_json = JSON.parse '[
  {
    "@id": "http://vocab.getty.edu/ulan/500115403",
    "http://xmlns.com/foaf/0.1/focus": [
      {
        "@id": "http://vocab.getty.edu/ulan/500115403-agent"
      }
    ],
    "http://www.w3.org/2004/02/skos/core#prefLabel": [
      {
        "@value": "Couture, Thomas"
      }
    ],
    "http://www.w3.org/2004/02/skos/core#inScheme": [
      {
        "@id": "http://vocab.getty.edu/ulan/"
      }
    ],
    "http://schema.org/url": [
      {
        "@id": "http://www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=500115403"
      }
    ]
  }
]'

frame = JSON.parse '{
  "@explicit": true,
  "@context": {
    "skos": "http://www.w3.org/2004/02/skos/core#",
    "foaf": "http://xmlns.com/foaf/0.1/",
    "schema": "http://schema.org/",
    "label": "skos:prefLabel",
    "id": "@id",
    "source": {
      "@id": "skos:inScheme",
      "@type": "@id"
    },
    "agent": {
      "@id": "foaf:focus",
      "@type": "@id"
    },
    "website": {
      "@id": "schema:url",
      "@type": "@id"
    }
  },
  "label": {},
  "id": {},
  "source": {},
  "agent": {},
  "website": {}
}'

puts JSON::LD::API.frame(unframed_json, frame)

returns

{
 "@context"=>{
  "skos"=>"http://www.w3.org/2004/02/skos/core#", 
  "foaf"=>"http://xmlns.com/foaf/0.1/", 
  "schema"=>"http://schema.org/", 
  "label"=>"skos:prefLabel", 
  "id"=>"@id",
   "source"=>{"@id"=>"skos:inScheme", "@type"=>"@id"}, 
   "agent"=>{"@id"=>"foaf:focus", "@type"=>"@id"}, 
   "website"=>{"@id"=>"schema:url", "@type"=>"@id"}
 }, 
 "@graph"=>[]
}

But when I put the same JSON into the JSON-LD Playground, I get the values I expect:

permalink to Playground

gkellogg commented 8 years ago

It looks like there's a difference in the implementations when @id is included in the frame. In your example, if you remove "id": {},, you should get the output you expect.

In the current draft, the behavior of @id is undefined. However, in a branch being considered to be merged (which you can see here), it is expected to be one or more IRI or BNodes, which are used to match. However, it seems consistent with other matching to interpret {} as a wild-card, so this is likely a bug in both the new spec and my implementation.

In the mean time, try just removing id from the frame.

workergnome commented 8 years ago

Thank you. That appears to be exactly what is going on, and your work-around solves my immediate problem.

gkellogg commented 7 years ago

This should be fully supported now.