Search in sources :

Example 1 with NodeValueInteger

use of org.apache.jena.sparql.expr.nodevalue.NodeValueInteger in project jena by apache.

the class TestFunctionExpansion method test_function_expansion_02.

@Test
public void test_function_expansion_02() {
    Expr e = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
    UserDefinedFunctionFactory.getFactory().add("http://example/square", e, new ArrayList<>(e.getVarsMentioned()));
    UserDefinedFunction f = (UserDefinedFunction) UserDefinedFunctionFactory.getFactory().create("http://example/square");
    f.build("http://example/square", new ExprList(new NodeValueInteger(3)));
    Expr actual = f.getActualExpr();
    Assert.assertFalse(e.equals(actual));
    Assert.assertEquals(0, actual.getVarsMentioned().size());
    Assert.assertEquals(new E_Multiply(new NodeValueInteger(3), new NodeValueInteger(3)), actual);
}
Also used : UserDefinedFunction(org.apache.jena.sparql.function.user.UserDefinedFunction) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) Test(org.junit.Test)

Example 2 with NodeValueInteger

use of org.apache.jena.sparql.expr.nodevalue.NodeValueInteger in project jena by apache.

the class TestOptimizer method combine_extend_01.

@Test
public void combine_extend_01() {
    Op extend = OpExtend.create(OpTable.unit(), new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
    extend = OpExtend.create(extend, new VarExprList(Var.alloc("y"), new NodeValueInteger(2)));
    String opExpectedString = StrUtils.strjoinNL("(extend ((?x 1) (?y 2))", "  (table unit))");
    check(extend, new TransformExtendCombine(), opExpectedString);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Example 3 with NodeValueInteger

use of org.apache.jena.sparql.expr.nodevalue.NodeValueInteger in project jena by apache.

the class TestOptimizer method combine_assign_03.

@Test
public void combine_assign_03() {
    Op assign = OpAssign.create(OpTable.unit(), new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
    assign = OpAssign.create(assign, new VarExprList(Var.alloc("x"), new NodeValueInteger(2)));
    String opExpectedString = StrUtils.strjoinNL("(assign ((?x 2))", "  (assign ((?x 1))", "    (table unit)))");
    check(assign, new TransformExtendCombine(), opExpectedString);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Example 4 with NodeValueInteger

use of org.apache.jena.sparql.expr.nodevalue.NodeValueInteger in project jena by apache.

the class TestFunctionExpansion method test_function_expansion_06.

@Test
public void test_function_expansion_06() {
    Expr takeaway = new E_Subtract(new ExprVar("x"), new ExprVar("y"));
    List<Var> args = new ArrayList<>();
    args.add(Var.alloc("x"));
    args.add(Var.alloc("y"));
    UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
    // Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
    ExprList numArgs = new ExprList();
    numArgs.add(new NodeValueInteger(1));
    numArgs.add(new NodeValueDouble(2.3));
    Expr test = new E_Function("http://example/takeaway", numArgs);
    UserDefinedFunctionFactory.getFactory().add("http://example/test", test, new ArrayList<Var>());
    UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/test");
    Expr base = def.getBaseExpr();
    Assert.assertTrue(base instanceof E_Subtract);
    E_Subtract subtract = (E_Subtract) base;
    Assert.assertTrue(subtract.getArg1() instanceof NodeValueInteger);
    Assert.assertTrue(subtract.getArg2() instanceof NodeValueDouble);
}
Also used : Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) NodeValueDouble(org.apache.jena.sparql.expr.nodevalue.NodeValueDouble) Test(org.junit.Test)

Example 5 with NodeValueInteger

use of org.apache.jena.sparql.expr.nodevalue.NodeValueInteger in project jena by apache.

the class SolutionModifierTest method testAddHavingString.

@ContractTest
public void testAddHavingString() throws ParseException {
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addHaving("?foo<10");
    Query query = builder.build();
    assertTrue(query.hasHaving());
    List<Expr> having = query.getHavingExprs();
    assertEquals(1, having.size());
    Expr exp = having.get(0);
    assertTrue(exp.isFunction());
    assertTrue(exp.getFunction() instanceof E_LessThan);
    List<Expr> args = exp.getFunction().getArgs();
    assertEquals(new ExprVar("foo"), args.get(0));
    assertEquals(new NodeValueInteger(10), args.get(1));
    builder = solutionModifier.addHaving("?bar < 10");
    query = builder.build();
    assertTrue(query.hasHaving());
    having = query.getHavingExprs();
    assertEquals(2, having.size());
    exp = having.get(0);
    assertTrue(exp.isFunction());
    assertTrue(exp.getFunction() instanceof E_LessThan);
    args = exp.getFunction().getArgs();
    assertEquals(new ExprVar("foo"), args.get(0));
    assertEquals(new NodeValueInteger(10), args.get(1));
    exp = having.get(1);
    assertTrue(exp.isFunction());
    assertTrue(exp.getFunction() instanceof E_LessThan);
    args = exp.getFunction().getArgs();
    assertEquals(new ExprVar("bar"), args.get(0));
    assertEquals(new NodeValueInteger(10), args.get(1));
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Query(org.apache.jena.query.Query) Expr(org.apache.jena.sparql.expr.Expr) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) E_LessThan(org.apache.jena.sparql.expr.E_LessThan) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)19 Test (org.junit.Test)16 Op (org.apache.jena.sparql.algebra.Op)7 VarExprList (org.apache.jena.sparql.core.VarExprList)7 ExprVar (org.apache.jena.sparql.expr.ExprVar)5 ArrayList (java.util.ArrayList)3 Var (org.apache.jena.sparql.core.Var)3 E_LessThan (org.apache.jena.sparql.expr.E_LessThan)3 Expr (org.apache.jena.sparql.expr.Expr)3 UserDefinedFunction (org.apache.jena.sparql.function.user.UserDefinedFunction)3 ContractTest (org.xenei.junit.contract.ContractTest)3 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)2 Node (org.apache.jena.graph.Node)2 NodeValue (org.apache.jena.sparql.expr.NodeValue)2 NodeValueDouble (org.apache.jena.sparql.expr.nodevalue.NodeValueDouble)2 ElementFilter (org.apache.jena.sparql.syntax.ElementFilter)2 Query (org.apache.jena.query.Query)1 NodeValueNode (org.apache.jena.sparql.expr.nodevalue.NodeValueNode)1