gjhiggins/rdflib — Issue #27: fix for GRAPH <some ctx> { ... }
Author: gjhiggins
Created: 2011-10-19 00:58:47+00:00
State: open
Labels: Type-Defect

Originally filed by drewpca on 2008-06-20T06:09:33

A query like
"SELECT ?s WHERE { GRAPH { ?s ?p ?o }}"
would fail in the svn version of rdflib. Below is a patch with a test case
that was failing, plus a simple fix to sparql/Algebra.py that seems to work.

Index: test/test_sparql_graph_graph_pattern.py
===================================================================
--- test/test_sparql_graph_graph_pattern.py	(revision 1460)
+++ test/test_sparql_graph_graph_pattern.py	(working copy)
@@ -1,5 +1,6 @@
-# -*- coding: UTF-8 -*-
+# -*- coding: utf-8 -*-
from rdflib import ConjunctiveGraph, URIRef, Literal, RDFS
+from rdflib.Graph import Graph
from StringIO import StringIO
import unittest

@@ -37,5 +38,20 @@
results == [doc1],
"expecting : %s . Got: %s"%([doc1],repr(results)))

+class TestSparqlGraph(unittest.TestCase):
+ """GRAPH <...> {...} blocks in a sparql query"""
+ def testGraph(self):
+ node = URIRef('http://example.com')
+ ctx = URIRef("http://example.com/other#context")
+ graph = ConjunctiveGraph()
+
+ subgraph = Graph(store=graph.store, identifier=ctx)
+ subgraph.add((node, node, node))
+
+ allQuads = list(graph.quads((None, None, None)))
+ self.assertEqual(allQuads, [(node, node, node, subgraph)])
+ q = "SELECT ?s WHERE { GRAPH {
?s ?p ?o }}"
+ self.assertEqual(len(list(graph.query(q))), 1)
+
Index: rdflib/sparql/Algebra.py
===================================================================
--- rdflib/sparql/Algebra.py	(revision 1460)
+++ rdflib/sparql/Algebra.py	(working copy)
@@ -1002,7 +1002,7 @@
#assert len(targetGraph) == 1
targetGraph = targetGraph[0]
else:
- targetGraph = Graph(tripleStore.store,graphName)
+ targetGraph = Graph(tripleStore.graph.store,graphName)
tripleStore = sparqlGraph.SPARQLGraph(targetGraph,
dSCompliance=\
DAWG_DATASET_COMPLIANCE)