Search in sources :

Example 1 with Expr

use of org.apache.jena.sparql.expr.Expr in project jena by apache.

the class PropFuncArg method asExprList.

/** @deprecated To be removed - use {@link #asExprList()} */
@Deprecated
public ExprList asExprList(PropFuncArg pfArg) {
    ExprList exprList = new ExprList();
    if (pfArg.isNode()) {
        Node n = pfArg.getArg();
        Expr expr = ExprUtils.nodeToExpr(n);
        exprList.add(expr);
        return exprList;
    }
    for (Node n : pfArg.getArgList()) {
        Expr expr = ExprUtils.nodeToExpr(n);
        exprList.add(expr);
    }
    return exprList;
}
Also used : Expr(org.apache.jena.sparql.expr.Expr) ExprList(org.apache.jena.sparql.expr.ExprList) Node(org.apache.jena.graph.Node)

Example 2 with Expr

use of org.apache.jena.sparql.expr.Expr in project jena by apache.

the class TestSSE_Builder method testExprForms.

private static void testExprForms(String str1, String str2) {
    Expr e1 = SSE.parseExpr(str1);
    Expr e2 = SSE.parseExpr(str2);
    assertEquals(str1 + " " + str2, e1, e2);
}
Also used : Expr(org.apache.jena.sparql.expr.Expr)

Example 3 with Expr

use of org.apache.jena.sparql.expr.Expr in project jena by apache.

the class TestSSE_Builder method testBuildExpr_02.

@Test
public void testBuildExpr_02() {
    Expr e = SSE.parseExpr("(isNumeric ?x)");
    assertTrue(e instanceof E_IsNumeric);
}
Also used : Expr(org.apache.jena.sparql.expr.Expr) E_IsNumeric(org.apache.jena.sparql.expr.E_IsNumeric) Test(org.junit.Test)

Example 4 with Expr

use of org.apache.jena.sparql.expr.Expr in project jena by apache.

the class FunctionBase method exec.

@Override
public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
    if (args == null)
        // The contract on the function interface is that this should not happen.
        throw new ARQInternalErrorException("FunctionBase: Null args list");
    List<NodeValue> evalArgs = new ArrayList<>();
    for (Expr e : args) {
        NodeValue x = e.eval(binding, env);
        evalArgs.add(x);
    }
    NodeValue nv = exec(evalArgs);
    return nv;
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) Expr(org.apache.jena.sparql.expr.Expr) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ArrayList(java.util.ArrayList)

Example 5 with Expr

use of org.apache.jena.sparql.expr.Expr in project webofneeds by researchstudio-sat.

the class SparqlSelectFunction method apply.

@Override
public List<T> apply(Dataset dataset) {
    boolean existingTransaction = dataset.isInTransaction();
    if (!existingTransaction) {
        dataset.begin(ReadWrite.READ);
    }
    Dataset result = DatasetFactory.createGeneral();
    result.begin(ReadWrite.WRITE);
    try {
        Query theQuery = this.getQuery();
        if (this.limit != null) {
            theQuery.setLimit(this.limit);
        }
        if (this.offset != null) {
            theQuery.setOffset(this.offset);
        }
        if (this.orderBy != null) {
            for (SortCondition sortCondition : this.orderBy) {
                theQuery.addOrderBy(sortCondition);
            }
        }
        if (this.havingCondiditions != null) {
            for (Expr havingCondition : this.havingCondiditions) {
                theQuery.addHavingCondition(havingCondition);
            }
        }
        QuerySolution binding = this.initialBinding;
        if (binding == null) {
            binding = new QuerySolutionMap();
        }
        List<T> ret = new ArrayList<>();
        try (QueryExecution queryExecution = QueryExecutionFactory.create(theQuery, dataset, binding)) {
            ResultSet resultSet = queryExecution.execSelect();
            while (resultSet.hasNext()) {
                ret.add(this.resultGenerator.apply(resultSet.next()));
            }
        }
        return ret;
    } finally {
        if (!existingTransaction) {
            dataset.end();
        }
        result.commit();
    }
}
Also used : SortCondition(org.apache.jena.query.SortCondition) Query(org.apache.jena.query.Query) Expr(org.apache.jena.sparql.expr.Expr) QuerySolution(org.apache.jena.query.QuerySolution) Dataset(org.apache.jena.query.Dataset) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution) QuerySolutionMap(org.apache.jena.query.QuerySolutionMap)

Aggregations

Expr (org.apache.jena.sparql.expr.Expr)186 Test (org.junit.Test)102 ExprVar (org.apache.jena.sparql.expr.ExprVar)33 Var (org.apache.jena.sparql.core.Var)29 ExprList (org.apache.jena.sparql.expr.ExprList)15 Op (org.apache.jena.sparql.algebra.Op)14 NodeValue (org.apache.jena.sparql.expr.NodeValue)12 Query (org.apache.jena.query.Query)11 ContractTest (org.xenei.junit.contract.ContractTest)11 Node (org.apache.jena.graph.Node)9 E_Random (org.apache.jena.sparql.expr.E_Random)9 ArrayList (java.util.ArrayList)8 VarExprList (org.apache.jena.sparql.core.VarExprList)8 SortCondition (org.apache.jena.query.SortCondition)7 E_Regex (org.apache.jena.sparql.expr.E_Regex)6 Triple (org.apache.jena.graph.Triple)5 E_LessThan (org.apache.jena.sparql.expr.E_LessThan)5 LibTestExpr (org.apache.jena.sparql.expr.LibTestExpr)5 E_Multiply (org.apache.jena.sparql.expr.E_Multiply)4 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)3