summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew Perttula <drewp@bigasterisk.com>2015-03-29 00:58:26 -0700
committerDrew Perttula <drewp@bigasterisk.com>2015-03-29 00:58:26 -0700
commit5d9a7b05b223a08028d0a7899789b5259741cb5a (patch)
tree61c6483dcade139fa177487208e99371f46ef92c
parent395a40101fe133d97f454ee61da0fc748a93b007 (diff)
downloadrdflib-5d9a7b05b223a08028d0a7899789b5259741cb5a.tar.gz
trig serializer wasn't including a @prefix line for the first graph's prefix
-rw-r--r--rdflib/plugins/serializers/trig.py17
-rw-r--r--test/test_trig.py15
2 files changed, 16 insertions, 16 deletions
diff --git a/rdflib/plugins/serializers/trig.py b/rdflib/plugins/serializers/trig.py
index 479aae4d..a151827c 100644
--- a/rdflib/plugins/serializers/trig.py
+++ b/rdflib/plugins/serializers/trig.py
@@ -32,6 +32,7 @@ class TrigSerializer(TurtleSerializer):
def preprocess(self):
for context in self.contexts:
self.store = context
+ self.getQName(context.identifier)
self._references = defaultdict(int)
self._subjects = {}
@@ -40,22 +41,6 @@ class TrigSerializer(TurtleSerializer):
self._contexts[context]=(self.orderSubjects(), self._subjects, self._references)
-
- def preprocessTriple(self, triple):
- s, p, o = triple
- self._references[o]+=1
- self._subjects[s] = True
- for i, node in enumerate(triple):
- if node in self.keywords:
- continue
- # Don't use generated prefixes for subjects and objects
- self.getQName(node, gen_prefix=(i == VERB))
- if isinstance(node, Literal) and node.datatype:
- self.getQName(node.datatype, gen_prefix=_GEN_QNAME_FOR_DT)
- p = triple[1]
- if isinstance(p, BNode):
- self._references[p]+=1
-
def reset(self):
super(TrigSerializer, self).reset()
self._contexts = {}
diff --git a/test/test_trig.py b/test/test_trig.py
index abcbe1b9..0f800af3 100644
--- a/test/test_trig.py
+++ b/test/test_trig.py
@@ -46,3 +46,18 @@ class TestTrig(unittest.TestCase):
self.assertEqual(len(re.findall(b("p2"), s)), 1)
self.assert_(b('{}') not in s) # no empty graphs!
+
+ def testRememberNamespace(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")))
+ # In 4.2.0 the first serialization would fail to include the
+ # prefix for the graph but later serialize() calls would work.
+ first_out = g.serialize(format='trig')
+ second_out = g.serialize(format='trig')
+ self.assertIn('@prefix ns1: <http://example.com/> .', second_out)
+ self.assertIn('@prefix ns1: <http://example.com/> .', first_out)
+
+ print first_out