Skip to content

Commit c956493

Browse files
committed
Merge pull request #536 from pchampin/fix-issue-535
fixed issue #535
2 parents e261af3 + 561d327 commit c956493

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

rdflib/plugins/parsers/nquads.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def parse(self, inputsource, sink, **kwargs):
4545
"""Parse f as an N-Triples file."""
4646
assert sink.store.context_aware, ("NQuadsParser must be given"
4747
" a context aware store.")
48-
self.sink = ConjunctiveGraph(store=sink.store)
48+
self.sink = ConjunctiveGraph(store=sink.store, identifier=sink.identifier)
4949

5050
source = inputsource.getByteStream()
5151

@@ -81,7 +81,7 @@ def parseline(self):
8181
obj = self.object()
8282
self.eat(r_wspace)
8383

84-
context = self.uriref() or self.nodeid()
84+
context = self.uriref() or self.nodeid() or self.sink.identifier
8585
self.eat(r_tail)
8686

8787
if self.line:

test/test_issue535.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from rdflib import ConjunctiveGraph, URIRef
2+
from rdflib.parser import StringInputSource
3+
4+
def test_nquads_default_graph():
5+
ds = ConjunctiveGraph()
6+
7+
data = """
8+
<http://example.org/s1> <http://example.org/p1> <http://example.org/o1> .
9+
<http://example.org/s2> <http://example.org/p2> <http://example.org/o2> .
10+
<http://example.org/s3> <http://example.org/p3> <http://example.org/o3> <http://example.org/g3> .
11+
"""
12+
13+
publicID = URIRef("http://example.org/g0")
14+
15+
ds.parse(data=data, format="nquads", publicID=publicID)
16+
17+
assert len(ds) == 3, len(g)
18+
assert len(list(ds.contexts())) == 2, len(list(ds.contexts()))
19+
assert len(ds.get_context(publicID)) == 2, len(ds.get_context(publicID))

0 commit comments

Comments
 (0)