示例#1
0
def evalModify(ctx, u):

    # Using replaces the dataset for evaluating the where-clause
    if u.using:
        otherDefault = False
        for d in u.using:
            if d.default:

                if not otherDefault:
                    # replace current default graph
                    dg = Graph()
                    ctx.pushGraph(dg)
                    otherDefault = True

                ctx.load(d.default, default=True)

            elif d.named:
                g = d.named
                ctx.load(g, default=False)

    # "The WITH clause provides a convenience for when an operation
    # primarily refers to a single graph. If a graph name is specified
    # in a WITH clause, then - for the purposes of evaluating the
    # WHERE clause - this will define an RDF Dataset containing a
    # default graph with the specified name, but only in the absence
    # of USING or USING NAMED clauses. In the presence of one or more
    # graphs referred to in USING clauses and/or USING NAMED clauses,
    # the WITH clause will be ignored while evaluating the WHERE
    # clause."
    if not u.using and u.withClause:
        g = ctx.dataset.get_context(u.withClause)
        ctx.pushGraph(g)

    res = evalPart(ctx, u.where)

    if u.using:
        if otherDefault:
            ctx.popGraph()  # restore original default graph
        if u.withClause:
            g = ctx.dataset.get_context(u.withClause)
            ctx.pushGraph(g)

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

            for g, q in u.delete.quads.iteritems():
                cg = ctx.dataset.get_context(c.get(g))
                cg -= _fillTemplate(q, c)

        if u.insert:
            dg += _fillTemplate(u.insert.triples, c)

            for g, q in u.insert.quads.iteritems():
                cg = ctx.dataset.get_context(c.get(g))
                cg += _fillTemplate(q, c)
示例#2
0
def evalModify(ctx, u):

    # Using replaces the dataset for evaluating the where-clause
    if u.using:
        otherDefault = False
        for d in u.using:
            if d.default:

                if not otherDefault:
                    # replace current default graph
                    dg = Graph()
                    ctx.pushGraph(dg)
                    otherDefault = True

                ctx.load(d.default, default=True)

            elif d.named:
                g = d.named
                ctx.load(g, default=False)

    # "The WITH clause provides a convenience for when an operation
    # primarily refers to a single graph. If a graph name is specified
    # in a WITH clause, then - for the purposes of evaluating the
    # WHERE clause - this will define an RDF Dataset containing a
    # default graph with the specified name, but only in the absence
    # of USING or USING NAMED clauses. In the presence of one or more
    # graphs referred to in USING clauses and/or USING NAMED clauses,
    # the WITH clause will be ignored while evaluating the WHERE
    # clause."
    if not u.using and u.withClause:
        g = ctx.dataset.get_context(u.withClause)
        ctx.pushGraph(g)

    res = evalPart(ctx, u.where)

    if u.using:
        if otherDefault:
            ctx.popGraph()  # restore original default graph
        if u.withClause:
            g = ctx.dataset.get_context(u.withClause)
            ctx.pushGraph(g)

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

            for g, q in u.delete.quads.iteritems():
                cg = ctx.dataset.get_context(g)
                cg -= _fillTemplate(q, c)

        if u.insert:
            dg += _fillTemplate(u.insert.triples, c)

            for g, q in u.insert.quads.iteritems():
                cg = ctx.dataset.get_context(g)
                cg += _fillTemplate(q, c)
示例#3
0
def Builtin_EXISTS(e, ctx):
    # damn...
    from rdflib_sparql.evaluate import evalPart

    exists = e.name == 'Builtin_EXISTS'

    ctx = ctx.thaw()
    for x in evalPart(ctx, e.graph):
        return Literal(exists)
    return Literal(not exists)