summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Aastrand Grimnes <gromgull@gmail.com>2017-02-14 14:22:11 +0100
committerGunnar Aastrand Grimnes <gromgull@gmail.com>2017-02-14 14:22:11 +0100
commitaa8bc5e703c36e0edd740e0f4357134f2ef3b69e (patch)
tree6493609c5c7ad886373b5a8a350f260beae5f601
parentcde90dae34bf7bbab60b0351a895cc85c2c0f628 (diff)
downloadrdflib-aa8bc5e703c36e0edd740e0f4357134f2ef3b69e.tar.gz
SPARQLStore: use ASK queries when all triple-parts are bound in .triples()
-rw-r--r--rdflib/plugins/stores/sparqlstore.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/rdflib/plugins/stores/sparqlstore.py b/rdflib/plugins/stores/sparqlstore.py
index 66382219..2be781d7 100644
--- a/rdflib/plugins/stores/sparqlstore.py
+++ b/rdflib/plugins/stores/sparqlstore.py
@@ -276,11 +276,12 @@ class SPARQLStore(NSSPARQLWrapper, Store):
if vars:
v = ' '.join([term.n3() for term in vars])
+ verb = 'SELECT %s '%v
else:
- v = '*'
+ verb = 'ASK'
nts = self.node_to_sparql
- query = "SELECT %s WHERE { %s %s %s }" % (v, nts(s), nts(p), nts(o))
+ query = "%s { %s %s %s }" % (verb, nts(s), nts(p), nts(o))
# The ORDER BY is necessary
if hasattr(context, LIMIT) or hasattr(context, OFFSET) \
@@ -315,10 +316,14 @@ class SPARQLStore(NSSPARQLWrapper, Store):
with contextlib.closing(SPARQLWrapper.query(self).response) as res:
result = Result.parse(res, format=self.returnFormat)
- for row in result:
- yield (row.get(s, s),
- row.get(p, p),
- row.get(o, o)), None
+ if vars:
+ for row in result:
+ yield (row.get(s, s),
+ row.get(p, p),
+ row.get(o, o)), None # why is the context here not the passed in graph 'context'?
+ else:
+ if result.askAnswer:
+ yield (s,p,o), None
def triples_choices(self, _, context=None):
"""