digitalbazaar/pyld

framing with "@embed": "@link" cannot handle circular references

Opened this issue · 2 comments

bpow commented

Framing with "@embed": "@link" has been proposed as one way to create an in-memory representation of a graph (as discussed in json-ld/json-ld.org#140 ).

jsonld.js does this in a way that handles circular references, but when I try to use pyld to frame:

{
  "@context": "http://schema.org/",
  "@type": "Person",
  "name": "Jane Doe",
  "jobTitle": "Professor",
  "telephone": "(425) 123-4567",
  "@id": "http://www.janedoe.com",
  "knows": {
    "name": "John Smith",
    "@type": "Person",
    "@id": "http://www.johnsmith.me",
    "knows": {
      "@id": "http://www.janedoe.com"
    }
  }
}

with a frame like:

{
  "@context": "http://schema.org",
  "@embed": "@link"
}

... I get a RuntimeError from exceeding the recursion limit.

I also demonstrate this in a gist

I doubt this feature has been tested. Sorry about that. The test suites need updates to check these newer features. The code was probably ported from jsonld.js long ago. Might be worth checking if it works in jsonld.js, and if so then compare the code to see what might have changed or not been ported properly.

bpow commented

jsonld.js is able to handle this case-- the code relevant was ported but did not "keep track" of nodes when linking because empty dicts in python evaluate to False.

I'm actually not sure how to write a test for this within the existing testing framework, since the framed result is not representable directly in json (so there is no way to write a [test]-[test#]-out.jsonld file as framing with '@embed' = '@link' is only intended to be used for an in-memory representation (from what I can tell).