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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations