Beispiel #1
0
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:
        res = []
        for graph in ctx.dataset.contexts():

            # in SPARQL the default graph is NOT a named graph
            if graph == ctx.dataset.default_context:
                continue

            ctx.pushGraph(graph)
            ctx.push()
            graphSolution = [{part.term: graph.identifier}]
            res += _join(evalPart(ctx, part.p), graphSolution)
            ctx.pop()
            ctx.popGraph()
        return res
    else:
        ctx.pushGraph(ctx.dataset.get_context(graph))
        return evalPart(ctx, part.p)
Beispiel #2
0
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:
        res = []
        for graph in ctx.dataset.contexts():

            # in SPARQL the default graph is NOT a named graph
            if graph == ctx.dataset.default_context:
                continue

            ctx.pushGraph(graph)
            ctx.push()
            graphSolution = [{part.term: graph.identifier}]
            res += _join(evalPart(ctx, part.p), graphSolution)
            ctx.pop()
            ctx.popGraph()
        return res
    else:
        ctx.pushGraph(ctx.dataset.get_context(graph))
        return evalPart(ctx, part.p)
Beispiel #3
0
def evalJoin(ctx, join):

    # TODO: Deal with dict returned from evalPart from GROUP BY
    # only ever for join.p1

    a = set(evalPart(ctx, join.p1))
    b = set(evalPart(ctx, join.p2))
    return _join(a, b)
Beispiel #4
0
def evalJoin(ctx, join):

    # TODO: Deal with dict returned from evalPart from GROUP BY
    # only ever for join.p1

    a = set(evalPart(ctx, join.p1))
    b = set(evalPart(ctx, join.p2))
    return _join(a, b)
Beispiel #5
0
def evalLeftJoin(ctx, join):

    a = set(evalPart(ctx, join.p1))
    b = set(evalPart(ctx, join.p2))
    res = set()
    res.update(_filter(_join(a, b), join.expr))
    res.update(_diff(a, b, join.expr))

    return res
Beispiel #6
0
def evalLeftJoin(ctx, join):

    a = set(evalPart(ctx, join.p1))
    b = set(evalPart(ctx, join.p2))
    res = set()
    res.update(_filter(_join(a, b), join.expr))
    res.update(_diff(a, b, join.expr))

    return res
Beispiel #7
0
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)
        ctx.pushGraph(cg)
        res = _join(res, evalBGP(ctx, u.quads[g]))
        ctx.popGraph()

    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)
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)
        ctx.pushGraph(cg)
        res = _join(res, evalBGP(ctx, u.quads[g]))
        ctx.popGraph()

    for c in res:
        g = ctx.graph
        g -= _fillTemplate(u.triples, c)

        for g in u.quads:
            cg = ctx.dataset.get_context(g)
            cg -= _fillTemplate(u.quads[g], c)