Package com.hp.hpl.jena.sparql.expr

Examples of com.hp.hpl.jena.sparql.expr.Expr


        Assert.assertTrue(subtract.getArg2() instanceof NodeValueInteger);
    }
   
    @Test
    public void test_function_expansion_08() {
        Expr takeaway = new E_Subtract(new ExprVar("x"), new ExprVar("y"));
        List<Var> args = new ArrayList<Var>();
        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 altArgs = new ExprList();
        altArgs.add(new ExprVar("a"));
        altArgs.add(new ExprVar("b"));
        ArrayList<Var> defArgs = new ArrayList<Var>();
        defArgs.add(Var.alloc("a"));
        defArgs.add(Var.alloc("b"));
        Expr test = new E_Function("http://example/takeaway", altArgs);
        UserDefinedFunctionFactory.getFactory().add("http://example/test", test, defArgs);
       
        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 ExprVar);
        Assert.assertTrue(subtract.getArg2() instanceof ExprVar);
        Assert.assertEquals(subtract.getArg1().getVarName(), "a");
View Full Code Here


        Assert.assertEquals(subtract.getArg2().getVarName(), "b");
    }
   
    @Test
    public void test_function_expansion_09() {
        Expr takeaway = new E_Subtract(new ExprVar("x"), new ExprVar("y"));
        List<Var> args = new ArrayList<Var>();
        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 altArgs = new ExprList();
        altArgs.add(new ExprVar("b"));
        altArgs.add(new ExprVar("a"));
        ArrayList<Var> defArgs = new ArrayList<Var>();
        defArgs.add(Var.alloc("a"));
        defArgs.add(Var.alloc("b"));
        Expr test = new E_Function("http://example/takeaway", altArgs);
        UserDefinedFunctionFactory.getFactory().add("http://example/test", test, defArgs);
       
        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 ExprVar);
        Assert.assertTrue(subtract.getArg2() instanceof ExprVar);
        Assert.assertEquals(subtract.getArg1().getVarName(), "b");
View Full Code Here

        Assert.assertEquals(subtract.getArg2().getVarName(), "a");
    }
   
    @Test
    public void test_function_expansion_10() {
        Expr single = new ExprVar("x");
        UserDefinedFunctionFactory.getFactory().add("http://example/single", single, new ArrayList<Var>(single.getVarsMentioned()));
       
        //Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
        //when the outer function has differing numbers of arguments
        List<Var> args = new ArrayList<Var>();
        args.add(Var.alloc("x"));
        args.add(Var.alloc("y"));
        Expr add = new E_Add(new E_Function("http://example/single", new ExprList(new ExprVar("x"))), new ExprVar("y"));
        UserDefinedFunctionFactory.getFactory().add("http://example/add", add, args);
       
        UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/add");
        Expr base = def.getBaseExpr();
        Assert.assertTrue(base instanceof E_Add);
        E_Add actual = (E_Add)base;
        Assert.assertTrue(actual.getArg1() instanceof ExprVar);
        Assert.assertTrue(actual.getArg2() instanceof ExprVar);
        Assert.assertEquals("x", actual.getArg1().getVarName());
View Full Code Here

        Assert.assertEquals("y", actual.getArg2().getVarName());
    }
   
    @Test
    public void test_function_expansion_11() {
        Expr single = new ExprVar("x");
        UserDefinedFunctionFactory.getFactory().add("http://example/single", single, new ArrayList<Var>(single.getVarsMentioned()));
       
        //Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
        //when the outer function has differing numbers of arguments
        List<Var> args = new ArrayList<Var>();
        args.add(Var.alloc("x"));
        args.add(Var.alloc("y"));
        Expr add = new E_Add(new E_Function("http://example/single", new ExprList(new ExprVar("y"))), new ExprVar("y"));
        UserDefinedFunctionFactory.getFactory().add("http://example/add", add, args);
       
        UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/add");
        Expr base = def.getBaseExpr();
        Assert.assertTrue(base instanceof E_Add);
        E_Add actual = (E_Add)base;
        Assert.assertTrue(actual.getArg1() instanceof ExprVar);
        Assert.assertTrue(actual.getArg2() instanceof ExprVar);
        Assert.assertEquals("y", actual.getArg1().getVarName());
View Full Code Here

        Assert.assertEquals("y", actual.getArg2().getVarName());
    }
   
    @Test
    public void test_function_expansion_12() {
        Expr takeaway = new E_Subtract(new ExprVar("x"), new ExprVar("y"));
        List<Var> args = new ArrayList<Var>();
        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 altArgs = new ExprList();
        altArgs.add(new ExprVar("a"));
        altArgs.add(new ExprVar("a"));
        ArrayList<Var> defArgs = new ArrayList<Var>();
        defArgs.add(Var.alloc("a"));
        defArgs.add(Var.alloc("b"));
        Expr test = new E_Function("http://example/takeaway", altArgs);
        UserDefinedFunctionFactory.getFactory().add("http://example/test", test, defArgs);
       
        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 ExprVar);
        Assert.assertTrue(subtract.getArg2() instanceof ExprVar);
        Assert.assertEquals(subtract.getArg1().getVarName(), "a");
View Full Code Here

        Assert.assertEquals(subtract.getArg2().getVarName(), "a");
    }
   
    @Test
    public void test_function_expansion_13() {
        Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
        UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));
       
        //This test illustrates that if we change the definition of square and call our function again we always
        //get the same result with dependencies not preserved because even though the definition of the dependent function
        //can change the definition of our function is fully expanded when first defined
        Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("x"))), new ExprVar("x"));
        UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<Var>(cube.getVarsMentioned()));
       
        UserDefinedFunction f = (UserDefinedFunction) UserDefinedFunctionFactory.getFactory().create("http://example/cube");
        f.build("http://example/cube", new ExprList(new NodeValueInteger(2)));
       
        Expr actual = f.getActualExpr();
        NodeValue result = actual.eval(BindingFactory.create(), FunctionEnvBase.createTest());
        Assert.assertEquals(8, NodeFactoryExtra.nodeToInt(result.asNode()));
       
        //Change the definition of the function we depend on
        //This has no effect with preserveDependencies set to false (the default) since we fully expanded the call to the dependent
        //function when our outer function was defined
        square = new ExprVar("x");
        UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));
        f.build("http://example/cube", new ExprList(new NodeValueInteger(2)));
       
        actual = f.getActualExpr();
        result = actual.eval(BindingFactory.create(), FunctionEnvBase.createTest());
        Assert.assertEquals(8, NodeFactoryExtra.nodeToInt(result.asNode()));
    }
View Full Code Here

    @Test(expected=ExprBuildException.class)
    public void test_function_expansion_bad_01() {
        List<Var> args = new ArrayList<Var>();
        args.add(Var.alloc("x"));
        args.add(Var.alloc("y"));
        Expr add = new E_Add(new ExprVar("x"), new ExprVar("y"));
       
        //It's an error to use a variable which is not mentioned in the argument list
        UserDefinedFunctionFactory.getFactory().add("http://example/add", add, new ArrayList<Var>());
    }
View Full Code Here

        UserDefinedFunctionFactory.getFactory().add("http://example/add", add, new ArrayList<Var>());
    }
   
    @Test(expected=ExprBuildException.class)
    public void test_function_expansion_bad_02() {
        Expr single = new ExprVar("x");
        UserDefinedFunctionFactory.getFactory().add("http://example/single", single, new ArrayList<Var>(single.getVarsMentioned()));
       
        //It's an error to use a variable which is not mentioned in the argument list, even in a call to a dependent function
        Expr test = new E_Function("http://example/single", new ExprList(new ExprVar("x")));
        UserDefinedFunctionFactory.getFactory().add("http://example/test", test, new ArrayList<Var>());
    }
View Full Code Here

        Assert.assertNotNull(factory);
    }
   
    @Test
    public void test_user_defined_function_factory_add_01() {
        Expr e = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
        UserDefinedFunctionFactory.getFactory().add("http://example/square", e, new ArrayList<Var>(e.getVarsMentioned()));
        Assert.assertTrue(UserDefinedFunctionFactory.getFactory().isRegistered("http://example/square"));
        Assert.assertEquals(e, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
    }
View Full Code Here

        Assert.assertEquals(e, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
    }
   
    @Test
    public void test_user_defined_function_factory_add_02() {
        Expr e1 = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
        Expr e2 = new E_Multiply(new ExprVar("y"), new ExprVar("y"));
       
        UserDefinedFunctionFactory.getFactory().add("http://example/square", e1, new ArrayList<Var>(e1.getVarsMentioned()));
        Assert.assertTrue(UserDefinedFunctionFactory.getFactory().isRegistered("http://example/square"));
        Assert.assertEquals(e1, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
       
        UserDefinedFunctionFactory.getFactory().add("http://example/square", e2, new ArrayList<Var>(e2.getVarsMentioned()));
        Assert.assertTrue(UserDefinedFunctionFactory.getFactory().isRegistered("http://example/square"));
        Assert.assertEquals(e2, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
    }
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.sparql.expr.Expr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.