Search in sources :

Example 51 with Expr

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

the class TestExpressions method testNumeric.

private static void testNumeric(String string, double d) {
    Expr expr = parse(string);
    NodeValue v = expr.eval(BindingFactory.binding(), new FunctionEnvBase());
    assertTrue(v.isDouble());
    assertEquals(d, v.getDouble(), 0);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) Expr(org.apache.jena.sparql.expr.Expr) FunctionEnvBase(org.apache.jena.sparql.function.FunctionEnvBase)

Example 52 with Expr

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

the class TestExpressions2 method eval.

// It's easier to write tests that simply are expected to return true/false 
/*package*/
static void eval(String string, boolean result) {
    Expr expr = ExprUtils.parse(string);
    NodeValue nv = expr.eval(null, FunctionEnvBase.createTest());
    boolean b = XSDFuncOp.booleanEffectiveValue(nv);
    assertEquals(string, result, b);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) Expr(org.apache.jena.sparql.expr.Expr)

Example 53 with Expr

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

the class SelectHandlerTest method testAddAggregateStringVar.

@Test
public void testAddAggregateStringVar() {
    Var v = Var.alloc("foo");
    handler.addVar("count(*)", v);
    VarExprList expr = query.getProject();
    assertEquals(1, expr.size());
    Expr e = expr.getExpr(Var.alloc("foo"));
    assertNotNull("expression should not be null", e);
    assertTrue("Should be an ExprAggregator", e instanceof ExprAggregator);
    assertTrue("Should be AggCount", ((ExprAggregator) e).getAggregator() instanceof AggCount);
}
Also used : Expr(org.apache.jena.sparql.expr.Expr) Var(org.apache.jena.sparql.core.Var) AggCount(org.apache.jena.sparql.expr.aggregate.AggCount) ExprAggregator(org.apache.jena.sparql.expr.ExprAggregator) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Example 54 with Expr

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

the class SelectHandlerTest method testAddStringWithPrefixVar.

@Test
public void testAddStringWithPrefixVar() {
    query.setPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
    Var v = Var.alloc("foo");
    handler.addVar("sum(xsd:integer(?V3))", v);
    VarExprList expr = query.getProject();
    assertEquals(1, expr.size());
    Expr e = expr.getExpr(Var.alloc("foo"));
    assertNotNull("expression should not be null", e);
    assertTrue("Should be an ExprAggregator", e instanceof ExprAggregator);
    assertTrue("Should contain an AggSum", ((ExprAggregator) e).getAggregator() instanceof AggSum);
}
Also used : Expr(org.apache.jena.sparql.expr.Expr) Var(org.apache.jena.sparql.core.Var) ExprAggregator(org.apache.jena.sparql.expr.ExprAggregator) AggSum(org.apache.jena.sparql.expr.aggregate.AggSum) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Example 55 with Expr

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

the class SelectHandlerTest method testAddExprVar.

@Test
public void testAddExprVar() {
    Var v = Var.alloc("foo");
    handler.addVar(new E_Random(), v);
    VarExprList expr = query.getProject();
    assertEquals(1, expr.size());
    Expr e = expr.getExpr(Var.alloc("foo"));
    assertNotNull("expression should not be null", e);
    assertTrue("Should be an E_Random", e instanceof E_Random);
}
Also used : Expr(org.apache.jena.sparql.expr.Expr) E_Random(org.apache.jena.sparql.expr.E_Random) Var(org.apache.jena.sparql.core.Var) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Aggregations

Expr (org.apache.jena.sparql.expr.Expr)83 Var (org.apache.jena.sparql.core.Var)28 ExprList (org.apache.jena.sparql.expr.ExprList)15 NodeValue (org.apache.jena.sparql.expr.NodeValue)15 Op (org.apache.jena.sparql.algebra.Op)13 ExprVar (org.apache.jena.sparql.expr.ExprVar)12 FunctionEnvBase (org.apache.jena.sparql.function.FunctionEnvBase)9 Test (org.junit.Test)9 VarExprList (org.apache.jena.sparql.core.VarExprList)8 Node (org.apache.jena.graph.Node)7 E_Random (org.apache.jena.sparql.expr.E_Random)7 ArrayList (java.util.ArrayList)6 Triple (org.apache.jena.graph.Triple)4 E_Multiply (org.apache.jena.sparql.expr.E_Multiply)4 E_Regex (org.apache.jena.sparql.expr.E_Regex)4 ContractTest (org.xenei.junit.contract.ContractTest)4 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)3 Query (org.apache.jena.query.Query)3 SortCondition (org.apache.jena.query.SortCondition)3 ExprAggregator (org.apache.jena.sparql.expr.ExprAggregator)3