Skip to content

JSON-LD @graph section is silently ignored on import #1699

@anatoly-scherbakov

Description

@anatoly-scherbakov

JSON-LD @graph section can be used to specify contents of a particular named graph identified by @id. When importing a document with such section into Graph, which is not context-aware, the contents of @graph section is lost. This is demonstrated by the following test failing under rdflib==6.0.1.

import json from rdflib import Graph, URIRef def test_jsonld_with_graph(): """Try to parse a JSON-LD document with a @graph entry in it.""" document = [ { '@id': 'https://spdx.org/licenses/', '@graph': [ { '@id': 'https://spdx.org/licenses/GPL-3.0-only', '@type': 'https://spdx.org/licenses/ListedLicense', }, ], }, ] graph = Graph() graph.parse( data=json.dumps(document), format='json-ld', ) assert ( URIRef('https://spdx.org/licenses/GPL-3.0-only'), URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), URIRef('https://spdx.org/licenses/ListedLicense'), ) in graph

If to replace Graph() with ConjunctiveGraph() in this test, it passes.

It can be argued that the behavior is logical, as plain Graph() cannot contain named graphs, — but perhaps an exception message would be helpful here? Just to let the user know what is going on, and what can be done. Otherwise, it might be hard to debug the problem. Maybe it is already discussed in the docs but I did not find it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions