Skip to content

Commit

Permalink
more sparql generators
Browse files Browse the repository at this point in the history
  • Loading branch information
gromgull committed Apr 30, 2013
1 parent 42cd5a6 commit be16dfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 10 additions & 10 deletions rdflib/plugins/sparql/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def evalUnion(ctx, union):


def evalMinus(ctx, minus):
a = set(evalPart(ctx, minus.p1))
a = evalPart(ctx, minus.p1)
b = set(evalPart(ctx, minus.p2))
return _minus(a, b)

Expand Down Expand Up @@ -164,7 +164,7 @@ def evalGraph(ctx, part):
ctx = ctx.clone()
graph = ctx[part.term]
if graph is None:
res = []

for graph in ctx.dataset.contexts():

# in SPARQL the default graph is NOT a named graph
Expand All @@ -174,12 +174,13 @@ def evalGraph(ctx, part):
c = ctx.pushGraph(graph)
c = c.push()
graphSolution = [{part.term: graph.identifier}]
res += _join(evalPart(c, part.p), graphSolution)
for x in _join(evalPart(c, part.p), graphSolution):
yield x

return res
else:
c = ctx.pushGraph(ctx.dataset.get_context(graph))
return evalPart(c, part.p)
for x in evalPart(c, part.p):
yield x


def evalValues(ctx, part):
Expand Down Expand Up @@ -287,17 +288,16 @@ def evalAggregateJoin(ctx, agg):
p = evalPart(ctx, agg.p)
# p is always a Group, we always get a dict back

res = []
for row in p:
bindings = {}
for a in agg.A:
evalAgg(a, p[row], bindings)

res.append(FrozenBindings(ctx, bindings))
yield FrozenBindings(ctx, bindings)

if len(p) == 0:
res.append(FrozenBindings(ctx))
return res
yield FrozenBindings(ctx)



def evalOrderBy(ctx, part):
Expand Down Expand Up @@ -431,7 +431,7 @@ def evalQuery(graph, query, initBindings, base=None):
if firstDefault:
# replace current default graph
dg = ctx.dataset.get_context(BNode())
ctx = c.pushGraph(dg)
ctx = ctx.pushGraph(dg)
firstDefault = True

ctx.load(d.default, default=True)
Expand Down
4 changes: 1 addition & 3 deletions rdflib/plugins/sparql/evalutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ def _diff(a, b, expr):


def _minus(a, b):
res = set()
for x in a:
if all((not x.compatible(y)) or x.disjointDomain(y) for y in b):
res.add(x)
yield x

return res


def _join(a, b):
Expand Down

0 comments on commit be16dfe

Please sign in to comment.