use of org.eclipse.rdf4j.query.algebra.ZeroLengthPath in project rdf4j by eclipse.
the class TupleExprBuilder method createPath.
private TupleExpr createPath(Scope scope, Var subjVar, TupleExpr pathExpression, Var endVar, Var contextVar, long length) throws VisitorException {
if (pathExpression instanceof StatementPattern) {
Var predVar = ((StatementPattern) pathExpression).getPredicateVar();
if (length == 0L) {
return new ZeroLengthPath(scope, subjVar, endVar, contextVar);
} else {
GraphPattern gp = new GraphPattern();
gp.setContextVar(contextVar);
gp.setStatementPatternScope(scope);
Var nextVar = null;
for (long i = 0L; i < length; i++) {
if (i < length - 1) {
nextVar = createAnonVar();
} else {
nextVar = endVar;
}
gp.addRequiredSP(subjVar, predVar, nextVar);
subjVar = nextVar;
}
return gp.buildTupleExpr();
}
} else {
if (length == 0L) {
return new ZeroLengthPath(scope, subjVar, endVar, contextVar);
} else {
GraphPattern gp = new GraphPattern();
gp.setContextVar(contextVar);
gp.setStatementPatternScope(scope);
Var nextVar = null;
for (long i = 0L; i < length; i++) {
if (i < length - 1L) {
nextVar = createAnonVar();
} else {
nextVar = endVar;
}
// create a clone of the path expression.
TupleExpr clone = pathExpression.clone();
VarReplacer replacer = new VarReplacer(endVar, nextVar);
clone.visit(replacer);
gp.addRequiredTE(clone);
subjVar = nextVar;
}
return gp.buildTupleExpr();
}
}
}
Aggregations