Search in sources :

Example 1 with ArbitraryLengthPath

use of org.eclipse.rdf4j.query.algebra.ArbitraryLengthPath in project rdf4j by eclipse.

the class TupleExprBuilder method handlePathModifiers.

private TupleExpr handlePathModifiers(Scope scope, Var subjVar, TupleExpr te, Var endVar, Var contextVar, long lowerBound, long upperBound) throws VisitorException {
    TupleExpr result = te;
    if (lowerBound >= 0L) {
        if (lowerBound < upperBound) {
            if (upperBound < Long.MAX_VALUE) {
                // upperbound is fixed-length
                // create set of unions for all path lengths between lower
                // and upper bound.
                Union union = new Union();
                Union currentUnion = union;
                for (long length = lowerBound; length < upperBound; length++) {
                    TupleExpr path = createPath(scope, subjVar, te, endVar, contextVar, length);
                    currentUnion.setLeftArg(path);
                    if (length == upperBound - 1) {
                        path = createPath(scope, subjVar, te, endVar, contextVar, length + 1);
                        currentUnion.setRightArg(path);
                    } else {
                        Union nextUnion = new Union();
                        currentUnion.setRightArg(nextUnion);
                        currentUnion = nextUnion;
                    }
                }
                ProjectionElemList pelist = new ProjectionElemList();
                for (String name : union.getAssuredBindingNames()) {
                    ProjectionElem pe = new ProjectionElem(name);
                    pelist.addElement(pe);
                }
                result = new Distinct(new Projection(union, pelist, false));
            } else {
                // upperbound is abitrary-length
                result = new ArbitraryLengthPath(scope, subjVar, te, endVar, contextVar, lowerBound);
            }
        } else {
            // create single path of fixed length.
            TupleExpr path = createPath(scope, subjVar, te, endVar, contextVar, lowerBound);
            result = path;
        }
    }
    return result;
}
Also used : ProjectionElemList(org.eclipse.rdf4j.query.algebra.ProjectionElemList) Distinct(org.eclipse.rdf4j.query.algebra.Distinct) Projection(org.eclipse.rdf4j.query.algebra.Projection) MultiProjection(org.eclipse.rdf4j.query.algebra.MultiProjection) ArbitraryLengthPath(org.eclipse.rdf4j.query.algebra.ArbitraryLengthPath) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Union(org.eclipse.rdf4j.query.algebra.Union) ProjectionElem(org.eclipse.rdf4j.query.algebra.ProjectionElem)

Aggregations

ArbitraryLengthPath (org.eclipse.rdf4j.query.algebra.ArbitraryLengthPath)1 Distinct (org.eclipse.rdf4j.query.algebra.Distinct)1 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)1 Projection (org.eclipse.rdf4j.query.algebra.Projection)1 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)1 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)1 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)1 Union (org.eclipse.rdf4j.query.algebra.Union)1