Search in sources :

Example 36 with ValueExpr

use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public ValueExpr visit(ASTInList node, Object data) throws VisitorException {
    ValueExpr leftArg = (ValueExpr) node.getValueExpr().jjtAccept(this, null);
    ValueExpr result = null;
    for (ASTValueExpr argExpr : node.getArgList().getElements()) {
        ValueExpr rightArg = (ValueExpr) argExpr.jjtAccept(this, null);
        if (result == null) {
            // First argument
            result = new SameTerm(leftArg, rightArg);
        } else {
            SameTerm sameTerm = new SameTerm(leftArg.clone(), rightArg);
            result = new Or(result, sameTerm);
        }
    }
    assert result != null;
    return result;
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) Or(org.eclipse.rdf4j.query.algebra.Or) ASTOr(org.eclipse.rdf4j.query.parser.serql.ast.ASTOr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) ASTSameTerm(org.eclipse.rdf4j.query.parser.serql.ast.ASTSameTerm) SameTerm(org.eclipse.rdf4j.query.algebra.SameTerm)

Example 37 with ValueExpr

use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public ValueExpr visit(ASTOr node, Object data) throws VisitorException {
    Iterator<ASTBooleanExpr> iter = node.getOperandList().iterator();
    ValueExpr result = (ValueExpr) iter.next().jjtAccept(this, null);
    while (iter.hasNext()) {
        ValueExpr operand = (ValueExpr) iter.next().jjtAccept(this, null);
        result = new Or(result, operand);
    }
    return result;
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) ASTBooleanExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTBooleanExpr) Or(org.eclipse.rdf4j.query.algebra.Or) ASTOr(org.eclipse.rdf4j.query.parser.serql.ast.ASTOr)

Example 38 with ValueExpr

use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public Regex visit(ASTRegex node, Object data) throws VisitorException {
    ValueExpr text = (ValueExpr) node.getText().jjtAccept(this, null);
    ValueExpr pattern = (ValueExpr) node.getPattern().jjtAccept(this, null);
    ValueExpr flags = null;
    if (node.hasFlags()) {
        flags = (ValueExpr) node.getFlags().jjtAccept(this, null);
    }
    return new Regex(text, pattern, flags);
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) ASTRegex(org.eclipse.rdf4j.query.parser.serql.ast.ASTRegex) Regex(org.eclipse.rdf4j.query.algebra.Regex)

Example 39 with ValueExpr

use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public TupleExpr visit(ASTSelect node, Object data) throws VisitorException {
    TupleExpr result = (TupleExpr) data;
    Extension extension = new Extension();
    ProjectionElemList projElemList = new ProjectionElemList();
    for (ASTProjectionElem projElemNode : node.getProjectionElemList()) {
        ValueExpr valueExpr = (ValueExpr) projElemNode.getValueExpr().jjtAccept(this, null);
        String alias = projElemNode.getAlias();
        if (alias != null) {
            // aliased projection element
            extension.addElement(new ExtensionElem(valueExpr, alias));
            projElemList.addElement(new ProjectionElem(alias));
        } else if (valueExpr instanceof Var) {
            // unaliased variable
            Var projVar = (Var) valueExpr;
            projElemList.addElement(new ProjectionElem(projVar.getName()));
        } else {
            throw new IllegalStateException("required alias for non-Var projection elements not found");
        }
    }
    if (!extension.getElements().isEmpty()) {
        extension.setArg(result);
        result = extension;
    }
    result = new Projection(result, projElemList);
    if (node.isDistinct()) {
        result = new Distinct(result);
    } else if (node.isReduced()) {
        result = new Reduced(result);
    }
    return result;
}
Also used : ProjectionElemList(org.eclipse.rdf4j.query.algebra.ProjectionElemList) ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) ASTVar(org.eclipse.rdf4j.query.parser.serql.ast.ASTVar) Var(org.eclipse.rdf4j.query.algebra.Var) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem) Projection(org.eclipse.rdf4j.query.algebra.Projection) ASTString(org.eclipse.rdf4j.query.parser.serql.ast.ASTString) ASTProjectionElem(org.eclipse.rdf4j.query.parser.serql.ast.ASTProjectionElem) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Reduced(org.eclipse.rdf4j.query.algebra.Reduced) Extension(org.eclipse.rdf4j.query.algebra.Extension) Distinct(org.eclipse.rdf4j.query.algebra.Distinct) ProjectionElem(org.eclipse.rdf4j.query.algebra.ProjectionElem) ASTProjectionElem(org.eclipse.rdf4j.query.parser.serql.ast.ASTProjectionElem)

Example 40 with ValueExpr

use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.

the class BasicGroup method filtersAsAnd.

private ValueExpr filtersAsAnd() {
    ValueExpr aExpr = null;
    for (ValueExpr aValEx : mFilters) {
        if (aExpr == null) {
            aExpr = aValEx;
        } else {
            And aAnd = new And();
            aAnd.setLeftArg(aValEx);
            aAnd.setRightArg(aExpr);
            aExpr = aAnd;
        }
    }
    return aExpr;
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) And(org.eclipse.rdf4j.query.algebra.And)

Aggregations

ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)55 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)19 Var (org.eclipse.rdf4j.query.algebra.Var)19 ASTValueExpr (org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr)14 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)10 ArrayList (java.util.ArrayList)9 Extension (org.eclipse.rdf4j.query.algebra.Extension)9 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)9 And (org.eclipse.rdf4j.query.algebra.And)7 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)7 Filter (org.eclipse.rdf4j.query.algebra.Filter)6 Projection (org.eclipse.rdf4j.query.algebra.Projection)6 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)6 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)6 List (java.util.List)5 Compare (org.eclipse.rdf4j.query.algebra.Compare)5 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)5 Reduced (org.eclipse.rdf4j.query.algebra.Reduced)5 BNodeGenerator (org.eclipse.rdf4j.query.algebra.BNodeGenerator)4 Distinct (org.eclipse.rdf4j.query.algebra.Distinct)4