Search in sources :

Example 21 with ValueConstant

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

the class TupleExprBuilder method visit.

@Override
public ValueExpr visit(ASTIn node, Object data) throws VisitorException {
    ValueExpr result = null;
    ValueExpr leftArg = (ValueExpr) data;
    int listItemCount = node.jjtGetNumChildren();
    if (listItemCount == 0) {
        result = new ValueConstant(BooleanLiteral.FALSE);
    } else if (listItemCount == 1) {
        ValueExpr arg = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, null);
        result = new Compare(leftArg, arg, CompareOp.EQ);
    } else {
        ListMemberOperator listMemberOperator = new ListMemberOperator();
        listMemberOperator.addArgument(leftArg);
        for (int i = 0; i < listItemCount; i++) {
            ValueExpr arg = (ValueExpr) node.jjtGetChild(i).jjtAccept(this, null);
            listMemberOperator.addArgument(arg);
        }
        result = listMemberOperator;
    }
    return result;
}
Also used : ListMemberOperator(org.eclipse.rdf4j.query.algebra.ListMemberOperator) ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) Compare(org.eclipse.rdf4j.query.algebra.Compare)

Example 22 with ValueConstant

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

the class QueryBuilderFactory method describe.

/**
 * Create a QueryBuilder for creating a describe query
 *
 * @param theVars
 *        the variables to be described
 * @param theValues
 *        the specific bound URI values to be described
 * @return a describe query builder
 */
public static QueryBuilder<ParsedGraphQuery> describe(String[] theVars, Resource... theValues) {
    QueryBuilder<ParsedGraphQuery> aBuilder = new AbstractQueryBuilder<ParsedGraphQuery>(new ParsedDescribeQuery());
    aBuilder.reduced();
    aBuilder.addProjectionVar("descr_subj", "descr_pred", "descr_obj");
    GroupBuilder<?, ?> aGroup = aBuilder.group();
    if (theVars != null) {
        for (String aVar : theVars) {
            Var aVarObj = new Var(aVar);
            aVarObj.setAnonymous(true);
            aGroup.filter().or(new SameTerm(aVarObj, new Var("descr_subj")), new SameTerm(aVarObj, new Var("descr_obj")));
        }
    }
    if (theValues != null) {
        for (Resource aVar : theValues) {
            Var aSubjVar = new Var("descr_subj");
            aSubjVar.setAnonymous(true);
            Var aObjVar = new Var("descr_obj");
            aObjVar.setAnonymous(true);
            aGroup.filter().or(new SameTerm(new ValueConstant(aVar), aSubjVar), new SameTerm(new ValueConstant(aVar), aObjVar));
        }
    }
    aGroup.atom("descr_subj", "descr_pred", "descr_obj");
    return aBuilder;
}
Also used : ParsedDescribeQuery(org.eclipse.rdf4j.query.parser.ParsedDescribeQuery) Var(org.eclipse.rdf4j.query.algebra.Var) ParsedGraphQuery(org.eclipse.rdf4j.query.parser.ParsedGraphQuery) SameTerm(org.eclipse.rdf4j.query.algebra.SameTerm) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) Resource(org.eclipse.rdf4j.model.Resource)

Example 23 with ValueConstant

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

the class TupleExprBuilder method visit.

@Override
public PropertySetElem visit(ASTPathOneInPropertySet node, Object data) throws VisitorException {
    PropertySetElem result = new PropertySetElem();
    result.setInverse(node.isInverse());
    ValueConstant predicate = (ValueConstant) node.jjtGetChild(0).jjtAccept(this, data);
    result.setPredicate(predicate);
    return result;
}
Also used : ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant)

Aggregations

ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)23 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)7 Var (org.eclipse.rdf4j.query.algebra.Var)7 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)6 IRI (org.eclipse.rdf4j.model.IRI)4 Compare (org.eclipse.rdf4j.query.algebra.Compare)4 Extension (org.eclipse.rdf4j.query.algebra.Extension)4 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)4 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)4 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)4 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)4 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)4 ArrayList (java.util.ArrayList)3 BNodeGenerator (org.eclipse.rdf4j.query.algebra.BNodeGenerator)3 EmptySet (org.eclipse.rdf4j.query.algebra.EmptySet)3 Projection (org.eclipse.rdf4j.query.algebra.Projection)3 Reduced (org.eclipse.rdf4j.query.algebra.Reduced)3 ASTValueExpr (org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr)3 ASTGraphOrDefault (org.eclipse.rdf4j.query.parser.sparql.ast.ASTGraphOrDefault)3 HashMap (java.util.HashMap)2