summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew Perttula <drewp@bigasterisk.com>2015-03-29 01:24:21 -0700
committerDrew Perttula <drewp@bigasterisk.com>2015-03-29 01:24:21 -0700
commitbd57db75f14e20aa7330624b671fb2160587dbd8 (patch)
tree949a82094dc6272c531dc05721f6fa848d674e11
parent5d9a7b05b223a08028d0a7899789b5259741cb5a (diff)
downloadrdflib-bd57db75f14e20aa7330624b671fb2160587dbd8.tar.gz
trig serializer corrections to graph label output
Before: "<short:name> {...}" and "<None> {...}" After: "short:name {...}" and "<http://actual/uri/here> {...}"
-rw-r--r--rdflib/plugins/serializers/trig.py5
-rw-r--r--test/test_trig.py20
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)