Search in sources :

Example 1 with NodeValueDouble

use of org.apache.jena.sparql.expr.nodevalue.NodeValueDouble 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) UserDefinedFunctionDefinition(org.apache.jena.sparql.function.user.UserDefinedFunctionDefinition) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) NodeValueDouble(org.apache.jena.sparql.expr.nodevalue.NodeValueDouble) Test(org.junit.Test)

Example 2 with NodeValueDouble

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

the class TestFunctionExpansion method test_function_expansion_07.

@Test
public void test_function_expansion_07() {
    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 NodeValueDouble(2.3));
    numArgs.add(new NodeValueInteger(1));
    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 NodeValueDouble);
    Assert.assertTrue(subtract.getArg2() instanceof NodeValueInteger);
}
Also used : Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList) UserDefinedFunctionDefinition(org.apache.jena.sparql.function.user.UserDefinedFunctionDefinition) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) NodeValueDouble(org.apache.jena.sparql.expr.nodevalue.NodeValueDouble) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Var (org.apache.jena.sparql.core.Var)2 NodeValueDouble (org.apache.jena.sparql.expr.nodevalue.NodeValueDouble)2 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)2 UserDefinedFunctionDefinition (org.apache.jena.sparql.function.user.UserDefinedFunctionDefinition)2 Test (org.junit.Test)2