Skip to content

Commit

Permalink
trig serializer corrections to graph label output
Browse files Browse the repository at this point in the history
Before: "<short:name> {...}" and "<None> {...}"
After: "short:name {...}" and "<http://actual/uri/here> {...}"
  • Loading branch information
drewp committed Mar 29, 2015
1 parent 5d9a7b0 commit bd57db7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rdflib/plugins/serializers/trig.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def serialize(self, stream, base=None, encoding=None,
if self.default_context and store.identifier==self.default_context:
self.write(self.indent() + '\n{')
else:
self.write(self.indent() + '\n<%s> {' % self.getQName(store.identifier))
iri = self.getQName(store.identifier)
if iri is None:
iri = '<%s>' % store.identifier
self.write(self.indent() + '\n%s {' % iri)

self.depth += 1
for subject in ordered_subjects:
Expand Down
20 changes: 20 additions & 0 deletions test/test_trig.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,23 @@ def testRememberNamespace(self):
self.assertIn('@prefix ns1: <http://example.com/> .', first_out)

print first_out

def testGraphQnameSyntax(self):
g = rdflib.ConjunctiveGraph()
g.add((rdflib.URIRef("http://example.com/s"),
rdflib.RDFS.label,
rdflib.Literal("example 1"),
rdflib.URIRef("http://example.com/graph1")))
out = g.serialize(format='trig')
self.assertIn('ns1:graph1 {', out)

def testGraphUriSyntax(self):
g = rdflib.ConjunctiveGraph()
g.add((rdflib.URIRef("http://example.com/s"),
rdflib.RDFS.label,
rdflib.Literal("example 1"),
# getQName will not abbreviate this, so it should come
# out as a '<...>' term.
rdflib.URIRef("http://example.com/foo.")))
out = g.serialize(format='trig')
self.assertIn('<http://example.com/foo.> {', out)

0 comments on commit bd57db7

Please sign in to comment.