Skip to content

Commit

Permalink
SPARQLStore: use ASK queries when all triple-parts are bound in .trip…
Browse files Browse the repository at this point in the history
…les()
  • Loading branch information
gromgull committed Feb 14, 2017
1 parent cde90da commit aa8bc5e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions rdflib/plugins/stores/sparqlstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,12 @@ def triples(self, spo, context=None):

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) \
Expand Down Expand Up @@ -315,10 +316,14 @@ def triples(self, spo, context=None):
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):
"""
Expand Down

0 comments on commit aa8bc5e

Please sign in to comment.