Search in sources :

Example 21 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TransformFilterEquality method processSpecialCase1.

private static List<Op> processSpecialCase1(List<Op> ops, List<Pair<Var, NodeValue>> equalities) {
    List<Op> ops2 = new ArrayList<>();
    Collection<Var> vars = varsMentionedInEqualityFilters(equalities);
    for (Op op : ops) {
        Op op2 = op;
        if (safeToTransform(vars, op)) {
            for (Pair<Var, NodeValue> p : equalities) op2 = processFilterWorker(op, p.getLeft(), p.getRight());
        }
        ops2.add(op2);
    }
    return ops2;
}
Also used : Op(org.apache.jena.sparql.algebra.Op) Var(org.apache.jena.sparql.core.Var)

Example 22 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TransformFilterEquality method preprocessFilterEquality.

// --- find and extract
private static Pair<List<Pair<Var, NodeValue>>, ExprList> preprocessFilterEquality(ExprList exprs) {
    List<Pair<Var, NodeValue>> exprsFilterEquality = new ArrayList<>();
    ExprList exprsOther = new ExprList();
    for (Expr e : exprs.getList()) {
        Pair<Var, NodeValue> p = preprocess(e);
        if (p != null)
            exprsFilterEquality.add(p);
        else
            exprsOther.add(e);
    }
    if (exprsFilterEquality.size() == 0)
        return null;
    return Pair.create(exprsFilterEquality, exprsOther);
}
Also used : VarExprList(org.apache.jena.sparql.core.VarExprList) Var(org.apache.jena.sparql.core.Var) Pair(org.apache.jena.atlas.lib.Pair)

Example 23 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TransformRemoveAssignment method processAssignments.

private VarExprList processAssignments(OpExtendAssign opAssign) {
    VarExprList orig = opAssign.getVarExprList();
    if (!orig.contains(this.var))
        return null;
    if (!orig.getExpr(this.var).equals(this.expr))
        return null;
    VarExprList modified = new VarExprList();
    for (Var v : orig.getVars()) {
        if (!v.equals(this.var)) {
            modified.add(v, orig.getExpr(v));
        }
    }
    if (modified.size() > 0 && modified.size() == orig.size())
        return null;
    return modified;
}
Also used : Var(org.apache.jena.sparql.core.Var) VarExprList(org.apache.jena.sparql.core.VarExprList)

Example 24 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class VariableUsageVisitor method visit.

@Override
public void visit(OpBGP opBGP) {
    Collection<Var> vars = new ArrayList<>();
    for (Triple t : opBGP.getPattern().getList()) {
        Vars.addVarsFromTriple(vars, t);
    }
    action(vars);
}
Also used : Triple(org.apache.jena.graph.Triple) Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList)

Example 25 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class VariableUsageVisitor method visit.

@Override
public void visit(OpExtend opExtend) {
    Collection<Var> vars = new ArrayList<>();
    for (Var var : opExtend.getVarExprList().getVars()) {
        vars.add(var);
        ExprVars.varsMentioned(vars, opExtend.getVarExprList().getExpr(var));
    }
    action(vars);
}
Also used : Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList)

Aggregations

Var (org.apache.jena.sparql.core.Var)264 Node (org.apache.jena.graph.Node)83 ArrayList (java.util.ArrayList)53 Test (org.junit.Test)47 Binding (org.apache.jena.sparql.engine.binding.Binding)33 VarExprList (org.apache.jena.sparql.core.VarExprList)30 Op (org.apache.jena.sparql.algebra.Op)29 Expr (org.apache.jena.sparql.expr.Expr)28 Triple (org.apache.jena.graph.Triple)17 HashMap (java.util.HashMap)15 ContractTest (org.xenei.junit.contract.ContractTest)13 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)12 Query (org.apache.jena.query.Query)11 ExprList (org.apache.jena.sparql.expr.ExprList)11 SortCondition (org.apache.jena.query.SortCondition)10 ExprVar (org.apache.jena.sparql.expr.ExprVar)10 HashSet (java.util.HashSet)9 Pair (org.apache.jena.atlas.lib.Pair)9 SqlColumn (org.apache.jena.sdb.core.sqlexpr.SqlColumn)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9