use of org.eclipse.rdf4j.query.algebra.And in project rdf4j by eclipse.
the class GraphPattern method addOptionalTE.
public void addOptionalTE(GraphPattern gp) {
List<ValueExpr> constraints = gp.removeAllConstraints();
TupleExpr tupleExpr = gp.buildTupleExpr();
OptionalTupleExpr optTE;
if (constraints.isEmpty()) {
optTE = new OptionalTupleExpr(tupleExpr);
} else {
ValueExpr constraint = constraints.get(0);
for (int i = 1; i < constraints.size(); i++) {
constraint = new And(constraint, constraints.get(i));
}
optTE = new OptionalTupleExpr(tupleExpr, constraint);
}
optionalTEs.add(optTE);
}
use of org.eclipse.rdf4j.query.algebra.And in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public ValueExpr visit(ASTNotIn node, Object data) throws VisitorException {
ValueExpr result = null;
ValueExpr leftArg = (ValueExpr) data;
int listItemCount = node.jjtGetNumChildren();
if (listItemCount == 0) {
result = new ValueConstant(BooleanLiteral.TRUE);
} else if (listItemCount == 1) {
ValueExpr arg = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, null);
result = new Compare(leftArg, arg, CompareOp.NE);
} else {
// create a set of conjunctive comparisons to represent the NOT IN
// operator: X NOT IN (a, b, c) -> X != a && X != b && X != c.
And and = new And();
And currentAnd = and;
for (int i = 0; i < listItemCount - 1; i++) {
ValueExpr arg = (ValueExpr) node.jjtGetChild(i).jjtAccept(this, null);
currentAnd.setLeftArg(new Compare(leftArg, arg, CompareOp.NE));
if (i == listItemCount - 2) {
// second-to-last item
arg = (ValueExpr) node.jjtGetChild(i + 1).jjtAccept(this, null);
currentAnd.setRightArg(new Compare(leftArg, arg, CompareOp.NE));
} else {
And newAnd = new And();
currentAnd.setRightArg(newAnd);
currentAnd = newAnd;
}
}
result = and;
}
return result;
}
use of org.eclipse.rdf4j.query.algebra.And in project rdf4j by eclipse.
the class GraphPattern method buildTupleExpr.
/**
* Builds a combined tuple expression from the tuple expressions and constraints in this graph pattern.
*
* @return A tuple expression for this graph pattern.
*/
public TupleExpr buildTupleExpr() {
TupleExpr result;
if (requiredTEs.isEmpty()) {
result = new SingletonSet();
} else {
result = requiredTEs.get(0);
for (int i = 1; i < requiredTEs.size(); i++) {
TupleExpr te = requiredTEs.get(i);
// if (containsProjection(te) || containsProjection(result))
// {
// result = new BottomUpJoin(result, te);
// }
// else {
result = new Join(result, te);
// }
}
}
for (Map.Entry<TupleExpr, List<ValueExpr>> entry : optionalTEs) {
List<ValueExpr> constraints = entry.getValue();
if (constraints != null && !constraints.isEmpty()) {
ValueExpr condition = constraints.get(0);
for (int i = 1; i < constraints.size(); i++) {
condition = new And(condition, constraints.get(i));
}
result = new LeftJoin(result, entry.getKey(), condition);
} else {
result = new LeftJoin(result, entry.getKey());
}
}
for (ValueExpr constraint : constraints) {
result = new Filter(result, constraint);
}
return result;
}
use of org.eclipse.rdf4j.query.algebra.And 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.And in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public Object visit(ASTAnd node, Object data) throws VisitorException {
ValueExpr leftArg = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, null);
ValueExpr rightArg = (ValueExpr) node.jjtGetChild(1).jjtAccept(this, null);
return new And(leftArg, rightArg);
}
Aggregations