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;
}
Aggregations