def evalGraph(ctx, part): if ctx.dataset is None: raise Exception("Non-conjunctive-graph doesn't know about " + "graphs. Try a query without GRAPH.") ctx = ctx.clone() graph = ctx[part.term] if graph is None: for graph in ctx.dataset.contexts(): # in SPARQL the default graph is NOT a named graph if graph == ctx.dataset.default_context: continue c = ctx.pushGraph(graph) c = c.push() graphSolution = [{part.term: graph.identifier}] for x in _join(evalPart(c, part.p), graphSolution): yield x else: c = ctx.pushGraph(ctx.dataset.get_context(graph)) for x in evalPart(c, part.p): yield x
def evalGraph(ctx, part): if ctx.dataset is None: raise Exception( "Non-conjunctive-graph doesn't know about " + "graphs. Try a query without GRAPH.") ctx = ctx.clone() graph = ctx[part.term] if graph is None: for graph in ctx.dataset.contexts(): # in SPARQL the default graph is NOT a named graph if graph == ctx.dataset.default_context: continue c = ctx.pushGraph(graph) c = c.push() graphSolution = [{part.term: graph.identifier}] for x in _join(evalPart(c, part.p), graphSolution): yield x else: c = ctx.pushGraph(ctx.dataset.get_context(graph)) for x in evalPart(c, part.p): yield x
def evalDeleteWhere(ctx, u): """ http://www.w3.org/TR/sparql11-update/#deleteWhere """ res = {} res["type_"] = "DELETEWHERE" res["delta"] = {} _res = evalBGP(ctx, u.triples) for g in u.quads: cg = ctx.dataset.get_context(g) c = ctx.pushGraph(cg) _res = _join(_res, list(evalBGP(c, u.quads[g]))) for c in _res: g = ctx.graph filled, filled_delta = tee(_fillTemplate(u.triples, c)) _append(res["delta"], 'default', 'removals', list(filled_delta)) g -= filled for g in u.quads: cg = ctx.dataset.get_context(c.get(g)) filledq, filledq_delta = tee(_fillTemplate(u.quads[g], c)) _append(res["delta"], cg.identifier, 'removals', list(filledq_delta)) cg -= filledq return res
def evalDeleteWhere(ctx, u): """ http://www.w3.org/TR/sparql11-update/#deleteWhere """ res = {} res["type"] = "DELETEWHERE" res["delta"] = {} _res = evalBGP(ctx, u.triples) for g in u.quads: cg = ctx.dataset.get_context(g) c = ctx.pushGraph(cg) _res = _join(_res, list(evalBGP(c, u.quads[g]))) for c in _res: g = ctx.graph filled, filled_delta = tee(_fillTemplate(u.triples, c)) _append(res["delta"], 'default', 'removals', list(filled_delta)) g -= filled for g in u.quads: cg = ctx.dataset.get_context(c.get(g)) filledq, filledq_delta = tee(_fillTemplate(u.quads[g], c)) _append(res["delta"], cg.identifier, 'removals', list(filledq_delta)) cg -= filledq return res
def evalJoin(ctx, join): # TODO: Deal with dict returned from evalPart from GROUP BY # only ever for join.p1 if join.lazy: return evalLazyJoin(ctx, join) else: a = evalPart(ctx, join.p1) b = set(evalPart(ctx, join.p2)) return _join(a, b)
def evalJoin(ctx, join): # TODO: Deal with dict returned from evalPart from GROUP BY # only ever for join.p1 # print 'evaluating join {}'.format(join) if join.lazy: return evalLazyJoin(ctx, join) else: a = evalPart(ctx, join.p1) b = set(evalPart(ctx, join.p2)) return _join(a, b)
def evalDeleteWhere(ctx, u): """ http://www.w3.org/TR/sparql11-update/#deleteWhere """ res = evalBGP(ctx, u.triples) for g in u.quads: cg = ctx.dataset.get_context(g) c = ctx.pushGraph(cg) res = _join(res, list(evalBGP(c, u.quads[g]))) for c in res: g = ctx.graph g -= _fillTemplate(u.triples, c) for g in u.quads: cg = ctx.dataset.get_context(c.get(g)) cg -= _fillTemplate(u.quads[g], c)