Search in sources :

Example 1 with QueryIterSlice

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

the class TextQueryPF method exec.

@Override
public QueryIterator exec(Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
    if (textIndex == null) {
        if (!warningIssued) {
            Log.warn(getClass(), "No text index - no text search performed");
            warningIssued = true;
        }
        // Not a text dataset - no-op
        return IterLib.result(binding, execCxt);
    }
    argSubject = Substitute.substitute(argSubject, binding);
    argObject = Substitute.substitute(argObject, binding);
    Node s = null;
    Node score = null;
    Node literal = null;
    if (argSubject.isList()) {
        // Length checked in build()
        s = argSubject.getArg(0);
        score = argSubject.getArg(1);
        if (!score.isVariable())
            throw new QueryExecException("Hit score is not a variable: " + argSubject);
        if (argSubject.getArgListSize() > 2) {
            literal = argSubject.getArg(2);
            if (!literal.isVariable())
                throw new QueryExecException("Hit literal is not a variable: " + argSubject);
        }
    } else {
        s = argSubject.getArg();
    }
    if (s.isLiteral())
        // Does not match
        return IterLib.noResults(execCxt);
    StrMatch match = objectToStruct(argObject, true);
    if (match == null) {
        // can't match
        return IterLib.noResults(execCxt);
    }
    // ----
    QueryIterator qIter = (Var.isVar(s)) ? variableSubject(binding, s, score, literal, match, execCxt) : concreteSubject(binding, s, score, literal, match, execCxt);
    if (match.getLimit() >= 0)
        qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt);
    return qIter;
}
Also used : QueryIterSlice(org.apache.jena.sparql.engine.iterator.QueryIterSlice) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) QueryExecException(org.apache.jena.query.QueryExecException)

Example 2 with QueryIterSlice

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

the class SpatialOperationPFBase method exec.

@Override
public QueryIterator exec(Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
    if (server == null) {
        if (!warningIssued) {
            Log.warn(getClass(), "No spatial index - no spatial search performed");
            warningIssued = true;
        }
        // Not a text dataset - no-op
        return IterLib.result(binding, execCxt);
    }
    argSubject = Substitute.substitute(argSubject, binding);
    argObject = Substitute.substitute(argObject, binding);
    if (!argSubject.isNode())
        throw new InternalErrorException("Subject is not a node (it was earlier!)");
    Node s = argSubject.getArg();
    if (s.isLiteral())
        // Does not match
        return IterLib.noResults(execCxt);
    SpatialMatch match = objectToStruct(argObject);
    if (match == null) {
        // can't match
        return IterLib.noResults(execCxt);
    }
    // ----
    QueryIterator qIter = (Var.isVar(s)) ? variableSubject(binding, s, match, execCxt) : concreteSubject(binding, s, match, execCxt);
    if (match.getLimit() >= 0)
        qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt);
    return qIter;
}
Also used : QueryIterSlice(org.apache.jena.sparql.engine.iterator.QueryIterSlice) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Aggregations

Node (org.apache.jena.graph.Node)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 QueryIterSlice (org.apache.jena.sparql.engine.iterator.QueryIterSlice)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1 QueryExecException (org.apache.jena.query.QueryExecException)1