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

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


        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<>();
        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<>();
        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);
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<>(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<>(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<>(square.getVarsMentioned()));
        f.build("http://example/cube", new ExprList(new NodeValueInteger(2)));
       
        actual = f.getActualExpr();
        result = actual.eval(BindingFactory.create(), FunctionEnvBase.createTest());
View Full Code Here

    @Test(expected=ExprBuildException.class)
    public void test_function_expansion_bad_01() {
        List<Var> args = new ArrayList<>();
        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<>(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

    @BeforeClass
    public static void setup() {
        UserDefinedFunctionFactory.getFactory().clear();
       
        //Define a square function
        Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
        UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<>(square.getVarsMentioned()));
    }
View Full Code Here

    }
   
    public void addOrderBy(String varName, int direction)
    {
        varName = Var.canonical(varName) ;
        SortCondition sc = new SortCondition(new ExprVar(varName), direction) ;
        addOrderBy(sc) ;
    }
View Full Code Here

{
    public static Expr nodeToExpr(Node n)
    {
        if ( n.isVariable() )
            return new ExprVar(n) ;
        return NodeValue.makeNode(n) ;
    }
View Full Code Here

    private void testSorting(int numBindings, int threshold)
    {
        List<Binding> unsorted = randomBindings(numBindings);
       
        List<SortCondition> conditions = new ArrayList<>();
        conditions.add(new SortCondition(new ExprVar("8"), Query.ORDER_ASCENDING));
        conditions.add(new SortCondition(new ExprVar("1"), Query.ORDER_ASCENDING));
        conditions.add(new SortCondition(new ExprVar("0"), Query.ORDER_DESCENDING));
        BindingComparator comparator = new BindingComparator(conditions);

        List<Binding> sorted = new ArrayList<>();
       
        SortedDataBag<Binding> db = new SortedDataBag<>(
View Full Code Here

    @Test public void testTemporaryFilesAreCleanedUpAfterCompletion()
    {
        List<Binding> unsorted = randomBindings(500);
       
        List<SortCondition> conditions = new ArrayList<>();
        conditions.add(new SortCondition(new ExprVar("8"), Query.ORDER_ASCENDING));
        BindingComparator comparator = new BindingComparator(conditions);
       
        SortedDataBag<Binding> db = new SortedDataBag<>(
                new ThresholdPolicyCount<Binding>(10),
                SerializationFactoryFinder.bindingSerializationFactory(),
View Full Code Here

    }
   
    @Test public void combine_extend_02()
    {
        Op extend = OpExtend.extendDirect(OpTable.unit(), new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
        extend = OpExtend.extendDirect(extend, new VarExprList(Var.alloc("y"), new ExprVar("x")));
       
        String opExpectedString = StrUtils.strjoinNL(
                                            "(extend ((?x 1) (?y ?x))",
                                            "  (table unit))");
       
View Full Code Here

TOP

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

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.