diff --git a/rdflib/plugins/parsers/nquads.py b/rdflib/plugins/parsers/nquads.py index bcbd7b036..f733078f9 100644 --- a/rdflib/plugins/parsers/nquads.py +++ b/rdflib/plugins/parsers/nquads.py @@ -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() @@ -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: diff --git a/test/test_issue535.py b/test/test_issue535.py new file mode 100644 index 000000000..15c6d0d39 --- /dev/null +++ b/test/test_issue535.py @@ -0,0 +1,19 @@ +from rdflib import ConjunctiveGraph, URIRef +from rdflib.parser import StringInputSource + +def test_nquads_default_graph(): + ds = ConjunctiveGraph() + + data = """ + . + . + . + """ + + 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))