Search in sources :

Example 41 with Var

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

the class SqlSelectBlock method merge.

// Calculate renames
// Map all vars in the scope to names in the rename.
private void merge(Scope scope, ScopeBase newScope, Generator gen) {
    String x = "";
    String sep = "";
    for (ScopeEntry e : scope.findScopes()) {
        SqlColumn oldCol = e.getColumn();
        Var v = e.getVar();
        String colName = gen.next();
        SqlColumn newCol = new SqlColumn(vTable, colName);
        this.add(new ColAlias(oldCol, newCol));
        newScope.setColumnForVar(v, newCol);
        // Annotations
        x = String.format("%s%s%s:(%s=>%s)", x, sep, v, oldCol, newCol);
        sep = " ";
    }
    if (x.length() > 0)
        addNote(x);
}
Also used : Var(org.apache.jena.sparql.core.Var) SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn)

Example 42 with Var

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

the class LeftJoinClassifier method nonLinearVars.

public static Set<Var> nonLinearVars(OpLeftJoin op) {
    Op left = effectiveOp(op.getLeft());
    Op right = effectiveOp(op.getRight());
    Set<Var> leftVars = OpVars.visibleVars(left);
    Set<Var> optRight = VarFinder.optDefined(right);
    return SetUtils.intersection(leftVars, optRight);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) Var(org.apache.jena.sparql.core.Var)

Example 43 with Var

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

the class ListBase method execEvaluated.

/** If the subject is a list (well, at least not an unbound variable), dispatch to execOneList
     *  else dispatch to one of object a var, a list or a node.
     */
@Override
public final QueryIterator execEvaluated(Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
    Node listNode = argSubject.getArg();
    if (!Var.isVar(listNode))
        // Subject bound or constant
        return execOneList(binding, listNode, predicate, argObject, execCxt);
    // Subject unbound.
    Var listVar = Var.alloc(listNode);
    return listUnboundSubject(binding, listVar, predicate, argObject, execCxt);
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node)

Example 44 with Var

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

the class CSVInput method vars.

private static List<Var> vars(CSVParser parser) {
    final List<Var> vars = new ArrayList<>();
    List<String> varNames = parser.parse1();
    if (varNames == null)
        throw new ARQException("SPARQL CSV Results malformed, input is empty");
    for (String vn : varNames) {
        vars.add(Var.alloc(vn));
    }
    return vars;
}
Also used : ARQException(org.apache.jena.sparql.ARQException) Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList)

Example 45 with Var

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

the class container method execEvaluatedCalc.

// Ask by finding all the rdf:_N + rdf:type  
private QueryIterator execEvaluatedCalc(Binding binding, Node containerNode, Node predicate, Node member, ExecutionContext execCxt) {
    Graph graph = execCxt.getActiveGraph();
    if (!containerNode.isVariable()) {
        // Container a ground term.
        if (!GraphContainerUtils.isContainer(execCxt.getActiveGraph(), containerNode, typeNode))
            return IterLib.noResults(execCxt);
        return oneContainer(binding, containerNode, member, execCxt);
    }
    // Container a variable. 
    Collection<Node> c = null;
    if (member.isVariable())
        c = findContainers(graph, typeNode);
    else
        c = findContainingContainers(graph, typeNode, member);
    QueryIterConcat cIter = new QueryIterConcat(execCxt);
    Var cVar = Var.alloc(containerNode);
    for (Node cn : c) {
        //Binding the container node. 
        Binding b = BindingFactory.binding(binding, cVar, cn);
        Node m = member;
        // Special case of ?x rdfs:member ?x
        if (Var.isVar(member) && member.equals(cVar)) {
            m = cn;
        }
        cIter.add(oneContainer(b, cn, m, execCxt));
    }
    return cIter;
//throw new QueryFatalException(Utils.className(this)+": Arg 1 is too hard : "+containerNode) ;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Graph(org.apache.jena.graph.Graph) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node)

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