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

default graph is not handled correctly #34

Closed
pchampin opened this issue Oct 21, 2015 · 3 comments
Closed

default graph is not handled correctly #34

pchampin opened this issue Oct 21, 2015 · 3 comments

Comments

@pchampin
Copy link

According to the JSON-LD specification:

When a JSON-LD document's top-level structure is an object that contains no other properties than @graph and optionally @context (properties that are not mapped to an IRI or a keyword are ignored), @graph is considered to express the otherwise implicit default graph.

Still, when parsing a JSON-LD file with a default graph into a ConjunctiveGraph,
I end up with the default_context of that ConjunctiveGraph being empty,
and the triples of the default graph stored in another context, identified with a blank node...

Example in the following code:

from StringIO import StringIO
from rdflib import ConjunctiveGraph
from rdflib.plugin import register, Parser
register('application/ld+json', Parser, 'rdflib_jsonld.parser', 'JsonLDParser')

f = StringIO("""
{
    "@context": "http://schema.org/",
    "@graph": [
        { "@id": "http://example.org/data#jdoe",
          "name": "John"
        },
        { "@id": "http://example.org/data#janedoe",
          "name": "Jane"
        },
        { "@id": "http://example.org/data#metadata",
          "@graph": [
              { "@id": "http://example.org/data",
                "creator": "http://example.org/data#janedoe"
              }
          ]
        }
    ]
}
""")

cg = ConjunctiveGraph()
cg.parse(f, format="application/ld+json")
print "conjunctive graph contains %s triples" % len(cg)
print "default graph contains %s triples (expected 2)" % len(cg.default_context)
for i in cg.contexts():
    print "other graph in cg (%s) contains %s triples" % (i.identifier, len(i))
@niklasl
Copy link
Member

niklasl commented Sep 1, 2016

This issue is dependent on RDFLib/rdflib#436. What you need here should possible by using the latest sources of rdflib and rdflib-jsonld and changing your parse invocation to:

cg.default_context.parse(f, format="application/ld+json")

If that works for you, can we close this specific case?

@pchampin
Copy link
Author

pchampin commented Sep 2, 2016

Your trick works (although I had to install rdflib and rdlib-jsonld from github rather than pypi). I agree to close this issue, as it is indeed a consequence of RDFLib/rdflib#436 .

@danbri
Copy link

danbri commented Mar 27, 2018

I can't see a default_context field on my Graph or ConjunctiveGraph objects (rdflib 4.2.2); has the API changed?

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

3 participants