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

fixed issue #535 #536

Merged
merged 2 commits into from
Nov 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rdflib/plugins/parsers/nquads.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def parse(self, inputsource, sink, **kwargs):
"""Parse f as an N-Triples file."""
assert sink.store.context_aware, ("NQuadsParser must be given"
" a context aware store.")
self.sink = ConjunctiveGraph(store=sink.store)
self.sink = ConjunctiveGraph(store=sink.store, identifier=sink.identifier)

source = inputsource.getByteStream()

Expand Down Expand Up @@ -81,7 +81,7 @@ def parseline(self):
obj = self.object()
self.eat(r_wspace)

context = self.uriref() or self.nodeid()
context = self.uriref() or self.nodeid() or self.sink.identifier
self.eat(r_tail)

if self.line:
Expand Down
19 changes: 19 additions & 0 deletions test/test_issue535.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from rdflib import ConjunctiveGraph, URIRef
from rdflib.parser import StringInputSource

def test_nquads_default_graph():
ds = ConjunctiveGraph()

data = """
<http://example.org/s1> <http://example.org/p1> <http://example.org/o1> .
<http://example.org/s2> <http://example.org/p2> <http://example.org/o2> .
<http://example.org/s3> <http://example.org/p3> <http://example.org/o3> <http://example.org/g3> .
"""

publicID = URIRef("http://example.org/g0")

ds.parse(data=data, format="nquads", publicID=publicID)

assert len(ds) == 3, len(g)
assert len(list(ds.contexts())) == 2, len(list(ds.contexts()))
assert len(ds.get_context(publicID)) == 2, len(ds.get_context(publicID))