Search in sources :

Example 1 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 2 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 3 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 4 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)

Example 5 with Var

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

the class strSplit method execEvaluated.

@Override
public QueryIterator execEvaluated(final Binding binding, final Node subject, final Node predicate, final PropFuncArg object, final ExecutionContext execCxt) {
    if (!Var.isVar(subject))
        throw new ExprEvalException("Subject is not a variable (" + subject + ")");
    if (object.getArgListSize() != 2)
        throw new ExprEvalException("Object list must contain exactly two arguments, the string to split and a regular expression");
    String s = object.getArg(0).getLiteralLexicalForm();
    String regex = object.getArg(1).getLiteralLexicalForm();
    final Var subjectVar = Var.alloc(subject);
    // StrUtils will also trim whitespace
    String[] tokens = StrUtils.split(s, regex);
    Iterator<Binding> it = Iter.map(Arrays.asList(tokens).iterator(), item -> BindingFactory.binding(binding, subjectVar, NodeFactory.createLiteral(item)));
    return new QueryIterPlainWrapper(it, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) Var(org.apache.jena.sparql.core.Var) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

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