use of org.eclipse.rdf4j.query.algebra.Compare in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public Compare visit(ASTCompare node, Object data) throws VisitorException {
ValueExpr leftArg = (ValueExpr) node.getLeftOperand().jjtAccept(this, null);
ValueExpr rightArg = (ValueExpr) node.getRightOperand().jjtAccept(this, null);
CompareOp operator = node.getOperator().getValue();
return new Compare(leftArg, rightArg, operator);
}
use of org.eclipse.rdf4j.query.algebra.Compare 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.Compare in project rdf4j by eclipse.
the class GroupBuilder method filter.
public GroupBuilder<T, E> filter(String theVar, Compare.CompareOp theOp, Value theValue) {
Compare aComp = new Compare(new Var(theVar), new ValueConstant(theValue), theOp);
mGroup.addFilter(aComp);
return this;
}
use of org.eclipse.rdf4j.query.algebra.Compare 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.Compare in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public Compare visit(ASTCompare 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 Compare(leftArg, rightArg, node.getOperator());
}
Aggregations