Search in sources :

Example 1 with E_Multiply

use of org.apache.jena.sparql.expr.E_Multiply in project jena by apache.

the class TestUserDefinedFunctionFactory method test_user_defined_function_factory_add_03.

@Test
public void test_user_defined_function_factory_add_03() throws ParseException {
    Expr e = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
    //Instead of registering the pre-built expression register using a string for the expression
    UserDefinedFunctionFactory.getFactory().add("http://example/square", "?x * ?x", new ArrayList<>(e.getVarsMentioned()));
    Assert.assertTrue(UserDefinedFunctionFactory.getFactory().isRegistered("http://example/square"));
    Assert.assertEquals(e, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) E_Multiply(org.apache.jena.sparql.expr.E_Multiply) Test(org.junit.Test)

Example 2 with E_Multiply

use of org.apache.jena.sparql.expr.E_Multiply in project jena by apache.

the class TestUserDefinedFunctionFactory method test_user_defined_function_factory_add_02.

@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<>(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<>(e2.getVarsMentioned()));
    Assert.assertTrue(UserDefinedFunctionFactory.getFactory().isRegistered("http://example/square"));
    Assert.assertEquals(e2, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) E_Multiply(org.apache.jena.sparql.expr.E_Multiply) Test(org.junit.Test)

Example 3 with E_Multiply

use of org.apache.jena.sparql.expr.E_Multiply in project jena by apache.

the class TestUserDefinedFunctionFactory method test_user_defined_function_factory_add_01.

@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<>(e.getVarsMentioned()));
    Assert.assertTrue(UserDefinedFunctionFactory.getFactory().isRegistered("http://example/square"));
    Assert.assertEquals(e, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) E_Multiply(org.apache.jena.sparql.expr.E_Multiply) Test(org.junit.Test)

Example 4 with E_Multiply

use of org.apache.jena.sparql.expr.E_Multiply in project jena by apache.

the class TestUserFunctionsInSparql method setup.

@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()));
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) E_Multiply(org.apache.jena.sparql.expr.E_Multiply) BeforeClass(org.junit.BeforeClass)

Aggregations

E_Multiply (org.apache.jena.sparql.expr.E_Multiply)4 Expr (org.apache.jena.sparql.expr.Expr)4 ExprVar (org.apache.jena.sparql.expr.ExprVar)4 Test (org.junit.Test)3 BeforeClass (org.junit.BeforeClass)1