Search in sources :

Example 1 with Compare

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);
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) ASTCompare(org.eclipse.rdf4j.query.parser.serql.ast.ASTCompare) Compare(org.eclipse.rdf4j.query.algebra.Compare) CompareOp(org.eclipse.rdf4j.query.algebra.Compare.CompareOp)

Example 2 with Compare

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;
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) And(org.eclipse.rdf4j.query.algebra.And) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) Compare(org.eclipse.rdf4j.query.algebra.Compare)

Example 3 with Compare

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;
}
Also used : Var(org.eclipse.rdf4j.query.algebra.Var) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) Compare(org.eclipse.rdf4j.query.algebra.Compare)

Example 4 with Compare

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;
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) Filter(org.eclipse.rdf4j.query.algebra.Filter) Var(org.eclipse.rdf4j.query.algebra.Var) And(org.eclipse.rdf4j.query.algebra.And) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) Join(org.eclipse.rdf4j.query.algebra.Join) Compare(org.eclipse.rdf4j.query.algebra.Compare) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Union(org.eclipse.rdf4j.query.algebra.Union)

Example 5 with Compare

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());
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) Compare(org.eclipse.rdf4j.query.algebra.Compare)

Aggregations

Compare (org.eclipse.rdf4j.query.algebra.Compare)6 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)5 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)4 And (org.eclipse.rdf4j.query.algebra.And)2 Var (org.eclipse.rdf4j.query.algebra.Var)2 CompareOp (org.eclipse.rdf4j.query.algebra.Compare.CompareOp)1 Filter (org.eclipse.rdf4j.query.algebra.Filter)1 Join (org.eclipse.rdf4j.query.algebra.Join)1 ListMemberOperator (org.eclipse.rdf4j.query.algebra.ListMemberOperator)1 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)1 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)1 Union (org.eclipse.rdf4j.query.algebra.Union)1 ASTCompare (org.eclipse.rdf4j.query.parser.serql.ast.ASTCompare)1 ASTValueExpr (org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr)1