use of org.eclipse.rdf4j.query.algebra.Union in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public Object visit(ASTPathExprUnion node, Object data) throws VisitorException {
Iterator<ASTPathExpr> args = node.getPathExprList().iterator();
// Create new sub-graph pattern for optional path expressions
TupleExpr unionExpr = parseGraphPattern(args.next()).buildTupleExpr();
while (args.hasNext()) {
TupleExpr argExpr = parseGraphPattern(args.next()).buildTupleExpr();
unionExpr = new Union(unionExpr, argExpr);
}
graphPattern.addRequiredTE(unionExpr);
return null;
}
use of org.eclipse.rdf4j.query.algebra.Union in project rdf4j by eclipse.
the class TupleExprBuilder method createTupleExprForNegatedPropertySet.
private TupleExpr createTupleExprForNegatedPropertySet(NegatedPropertySet nps, int index) {
Var subjVar = nps.getSubjectVar();
Var predVar = createAnonVar();
ValueExpr filterCondition = null;
ValueExpr filterConditionInverse = null;
// build (inverted) filter conditions for each negated path element.
for (PropertySetElem elem : nps.getPropertySetElems()) {
ValueConstant predicate = elem.getPredicate();
if (elem.isInverse()) {
Compare compare = new Compare(predVar, predicate, CompareOp.NE);
if (filterConditionInverse == null) {
filterConditionInverse = compare;
} else {
filterConditionInverse = new And(compare, filterConditionInverse);
}
} else {
Compare compare = new Compare(predVar, predicate, CompareOp.NE);
if (filterCondition == null) {
filterCondition = compare;
} else {
filterCondition = new And(compare, filterCondition);
}
}
}
TupleExpr patternMatch = null;
// one item)
if (filterCondition != null) {
for (ValueExpr objVar : nps.getObjectList()) {
if (patternMatch == null) {
patternMatch = new StatementPattern(nps.getScope(), subjVar, predVar, (Var) objVar, nps.getContextVar());
} else {
patternMatch = new Join(new StatementPattern(nps.getScope(), subjVar, predVar, (Var) objVar, nps.getContextVar()), patternMatch);
}
}
}
TupleExpr patternMatchInverse = null;
// one item):
if (filterConditionInverse != null) {
for (ValueExpr objVar : nps.getObjectList()) {
if (patternMatchInverse == null) {
patternMatchInverse = new StatementPattern(nps.getScope(), (Var) objVar, predVar, subjVar, nps.getContextVar());
} else {
patternMatchInverse = new Join(new StatementPattern(nps.getScope(), (Var) objVar, predVar, subjVar, nps.getContextVar()), patternMatchInverse);
}
}
}
TupleExpr completeMatch = null;
if (patternMatch != null) {
completeMatch = new Filter(patternMatch, filterCondition);
}
if (patternMatchInverse != null) {
if (completeMatch == null) {
completeMatch = new Filter(patternMatchInverse, filterConditionInverse);
} else {
completeMatch = new Union(new Filter(patternMatchInverse, filterConditionInverse), completeMatch);
}
}
return completeMatch;
}
use of org.eclipse.rdf4j.query.algebra.Union 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;
}
use of org.eclipse.rdf4j.query.algebra.Union in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public Object visit(ASTUnionGraphPattern node, Object data) throws VisitorException {
GraphPattern parentGP = graphPattern;
graphPattern = new GraphPattern(parentGP);
node.jjtGetChild(0).jjtAccept(this, null);
TupleExpr leftArg = graphPattern.buildTupleExpr();
graphPattern = new GraphPattern(parentGP);
node.jjtGetChild(1).jjtAccept(this, null);
TupleExpr rightArg = graphPattern.buildTupleExpr();
parentGP.addRequiredTE(new Union(leftArg, rightArg));
graphPattern = parentGP;
return null;
}
use of org.eclipse.rdf4j.query.algebra.Union in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public TupleExpr visit(ASTGraphUnion node, Object data) throws VisitorException {
TupleExpr leftArg = (TupleExpr) node.getLeftArg().jjtAccept(this, null);
TupleExpr rightArg = (TupleExpr) node.getRightArg().jjtAccept(this, null);
TupleExpr result = new Union(leftArg, rightArg);
if (node.isDistinct()) {
result = new Distinct(result);
}
return result;
}
Aggregations