diff --git a/rdflib/graph.py b/rdflib/graph.py index 6ee6d91ea..1fe680ac5 100644 --- a/rdflib/graph.py +++ b/rdflib/graph.py @@ -1342,8 +1342,10 @@ def parse(self, source=None, publicID=None, format="xml", source=source, publicID=publicID, location=location, file=file, data=data, format=format) - # id = self.context_id(self.absolutize(source.getPublicId())) - g_id = URIRef(publicID and publicID or source.getPublicId()) + g_id = publicID and publicID or source.getPublicId() + if not isinstance(g_id, Node): + g_id = URIRef(g_id) + context = Graph(store=self.store, identifier=g_id) context.remove((None, None, None)) context.parse(source, publicID=publicID, format=format, diff --git a/test/test_conjunctive_graph.py b/test/test_conjunctive_graph.py index 14605f16c..bc33e9b84 100644 --- a/test/test_conjunctive_graph.py +++ b/test/test_conjunctive_graph.py @@ -1,5 +1,5 @@ -from rdflib.graph import ConjunctiveGraph -from rdflib.term import Identifier, URIRef +from rdflib import ConjunctiveGraph +from rdflib.term import Identifier, URIRef, BNode from rdflib.parser import StringInputSource from os import path @@ -10,6 +10,23 @@ PUBLIC_ID = u"http://example.org/record/1" +def test_bnode_publicid(): + + g = ConjunctiveGraph() + b = BNode() + data = ' .' + print ("Parsing '{}' into {}".format(data, repr(b))) + g.parse(data=data, format='turtle', publicID=b) + + triples = list( g.get_context(b).triples((None,None,None)) ) + if not triples: + raise Exception("No triples found in graph {}".format(repr(b))) + + u = URIRef(b) + + triples = list( g.get_context(u).triples((None,None,None)) ) + if triples: + raise Exception("Bad: Found in graph {}: {}".format(repr(u), triples)) def test_graph_ids(): def check(kws):