Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bpow opened this issue Sep 12, 2017 · 2 comments
Open

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

bpow opened this issue Sep 12, 2017 · 2 comments

Comments

@bpow
Copy link
Contributor

bpow commented Sep 12, 2017

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

@davidlehn
Copy link
Member

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 added a commit to bpow/pyld that referenced this issue Sep 19, 2017
An empty dict is not truthy in python, so cannot just check
for "if options['link']"

Fixes digitalbazaar#64
@bpow
Copy link
Contributor Author

bpow commented Sep 19, 2017

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).

bpow added a commit to bpow/pyld that referenced this issue Oct 19, 2017
An empty dict is not truthy in python, so cannot just check
for "if options['link']"

Fixes digitalbazaar#64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants