diff options
-rw-r--r-- | rdflib/plugins/serializers/trig.py | 5 | ||||
-rw-r--r-- | test/test_trig.py | 20 |
2 files changed, 24 insertions, 1 deletions
diff --git a/rdflib/plugins/serializers/trig.py b/rdflib/plugins/serializers/trig.py index a151827c..b30d10c8 100644 --- a/rdflib/plugins/serializers/trig.py +++ b/rdflib/plugins/serializers/trig.py @@ -68,7 +68,10 @@ class TrigSerializer(TurtleSerializer): 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: diff --git a/test/test_trig.py b/test/test_trig.py index 0f800af3..862bff12 100644 --- a/test/test_trig.py +++ b/test/test_trig.py @@ -61,3 +61,23 @@ class TestTrig(unittest.TestCase): 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) |