Skip to content

Commit

Permalink
bnode as public id for graph.parse. test + fixes #300.
Browse files Browse the repository at this point in the history
  • Loading branch information
gromgull committed Jun 15, 2013
1 parent f5da2a2 commit a06fa67
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 4 additions & 2 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

This comment has been minimized.

Copy link
@joernhees

joernhees Jun 16, 2013

Member

I think this allows Literals? Is that wanted?

This comment has been minimized.

Copy link
@joernhees

joernhees Jun 16, 2013

Member

does it help to mention issue #300 to make this pop up somewhere?

This comment has been minimized.

Copy link
@gromgull

gromgull Jun 16, 2013

Author Member

I dont see why not?

In [1]: import rdflib

In [2]: g=rdflib.Graph()

In [3]: g.add( ( rdflib.Literal('RDFLib'), rdflib.Literal('isnt really'), rdflib.Literal('holding you to the RDF model')))

In [4]: list(g)
Out[4]: 
[(rdflib.term.Literal(u'RDFLib'),
  rdflib.term.Literal(u'isnt really'),
  rdflib.term.Literal(u'holding you to the RDF model'))]

In [6]: print g.serialize(format='n3')
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

"RDFLib" "isnt really" "holding you to the RDF model" .

:)

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,
Expand Down
21 changes: 19 additions & 2 deletions test/test_conjunctive_graph.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,6 +10,23 @@

PUBLIC_ID = u"http://example.org/record/1"

def test_bnode_publicid():

g = ConjunctiveGraph()
b = BNode()
data = '<d:d> <e:e> <f:f> .'
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):
Expand Down

0 comments on commit a06fa67

Please sign in to comment.