-
Notifications
You must be signed in to change notification settings - Fork 572
Failed to parse graph (json-ld, JSONDecodeError) #1423
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
Comments
Same here, finally RDFLib announces that JSON-LD (arguably the most used form of RDF) is supported without the need for a weird plugin! But apparently the changes has been push to prod without being tested for common use cases It seems to be broken when the I installed from rdflib import Graph
g = Graph()
g.parse(data=rdf_data, format='json-ld') I tried with rdf_data as a So I guess Note that Not sure if this is the same issue here, but for some reason Google did not implemented Content-Negociation on https://schema.org (yes the most commonly used Schema is not proper linked data) So you can't just ask for
Ironic no? |
@lambdamusic indeed it is due to the fact that http://schema.org/ does not work with content-negotiation A quick workaround would be to edit the I was facing more encoding issue, so I needed to install and use the PyLD package... cf. issue #1416 (comment) And you also need to convert your dict to a It feels a bit ridiculous to add again 2 additional libs to parse basic RDF, but a working process to parse JSON-LD will look like this: from pyld import jsonld
import json
if rdf_data['@context'].startswith('http://schema.org'):
rdf_data['@context'] = 'https://schema.org/docs/jsonldcontext.json'
rdf_data = jsonld.expand(rdf_data)
rdf_data = json.dumps(rdf_data)
g.parse(data=rdf_data, format='json-ld') You can read more about schema.org not supporting content negotiation here: schemaorg/schemaorg#2578 To properly resolve schema.org context run this:
You will see:
The rule is stated here: https://www.w3.org/TR/json-ld11/#interpreting-json-as-json-ld
Since this fails with RDFLib I guess RDFLib did not implemented this process, hence JSON-LD specifications are still not supported by RDFLib (would be nice to make it clear, because it can be confusing for some people who think the JSON-LD standard is supported) |
Update on resolving this issue: there is something implemented here that should extract the links (not sure if it is properly triggered for http://schema.org), I will take a look into it when I will have the time to set up a clean environment to test RDFLib: |
@vemonet
There is a comment in jsonld method 'src_to_json': That sounds like a sensible solution, now that jsonld is part of RDFLib. I'm adding content-negotiation by Link header (using rel="alternates") into the URLInputSource code in rdflib |
@ashleysommer thanks a lot! I was actually just looking into where the issue could come from, and was around there too: I'll take a look in your changes to better understand the problem! And try your pull request tomorrow btw it seems like issue #1416 is related to the same return json.load(StringIO(stream.read().decode("utf-8"))) |
I've made some changes to that line, in my new PR in order to try to prevent yet another copy of the data in the input chain. That might've incidentally fixed #1416 in some cases (eg, if the input string was already decoded at some point), but probably not in all cases. I'll test it. |
Thanks a lot @ashleysommer ! I tested it with my RDF snippets and it works, also fixing #1416 I can add a few tests also once your PR will be merged if you want, I just need to add some here https://github.com/RDFLib/rdflib/tree/master/test/jsonld/1.1/toRdf ? |
Thanks @vemonet @ashleysommer for looking into this! |
I've got a little json-ld snippet that works fine with https://www.easyrdf.org/converter but it can't be loaded by rdflib (6.0.1, py 3.9). What is going wrong?
This is
periodical.json
And the full traceback:
The text was updated successfully, but these errors were encountered: