Search in sources :

Example 1 with QueryIterYieldN

use of org.apache.jena.sparql.engine.iterator.QueryIterYieldN in project jena by apache.

the class PathLib method evalGroundedPath.

// Subject and object are nodes.
private static QueryIterator evalGroundedPath(Binding binding, Graph graph, Node subject, Path path, Node object, ExecutionContext execCxt) {
    Iterator<Node> iter = PathEval.eval(graph, subject, path, execCxt.getContext());
    // Now count the number of matches.
    int count = 0;
    for (; iter.hasNext(); ) {
        Node n = iter.next();
        if (n.sameValueAs(object))
            count++;
    }
    return new QueryIterYieldN(count, binding, execCxt);
}
Also used : Node(org.apache.jena.graph.Node) QueryIterYieldN(org.apache.jena.sparql.engine.iterator.QueryIterYieldN)

Example 2 with QueryIterYieldN

use of org.apache.jena.sparql.engine.iterator.QueryIterYieldN in project jena by apache.

the class PathLib method execUngroundedPathSameVar.

private static QueryIterator execUngroundedPathSameVar(Binding binding, Graph graph, Var var, Path path, ExecutionContext execCxt) {
    // Try each end, ungrounded.
    // Slightly more efficient would be to add a per-engine to do this.
    Iterator<Node> iter = determineUngroundedStartingSet(graph, path, execCxt);
    QueryIterConcat qIterCat = new QueryIterConcat(execCxt);
    for (; iter.hasNext(); ) {
        Node n = iter.next();
        Binding b2 = BindingFactory.binding(binding, var, n);
        int x = existsPath(graph, n, path, n, execCxt);
        if (x > 0) {
            QueryIterator qIter = new QueryIterYieldN(x, b2, execCxt);
            qIterCat.add(qIter);
        }
    }
    return qIterCat;
}
Also used : QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) QueryIterYieldN(org.apache.jena.sparql.engine.iterator.QueryIterYieldN)

Aggregations

Node (org.apache.jena.graph.Node)2 QueryIterYieldN (org.apache.jena.sparql.engine.iterator.QueryIterYieldN)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 QueryIterConcat (org.apache.jena.sparql.engine.iterator.QueryIterConcat)1