Search in sources :

Example 46 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar 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 47 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar 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)

Example 48 with ExprVar

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

the class TestOptimizer method combine_extend_02.

@Test
public void combine_extend_02() {
    Op extend = OpExtend.create(OpTable.unit(), new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
    extend = OpExtend.create(extend, new VarExprList(Var.alloc("y"), new ExprVar("x")));
    String opExpectedString = StrUtils.strjoinNL("(extend ((?x 1) (?y ?x))", "  (table unit))");
    check(extend, new TransformExtendCombine(), opExpectedString);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Op(org.apache.jena.sparql.algebra.Op) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Example 49 with ExprVar

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

the class TestOptimizer method combine_assign_02.

@Test
public void combine_assign_02() {
    Op assign = OpAssign.create(OpTable.unit(), new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
    assign = OpAssign.create(assign, new VarExprList(Var.alloc("y"), new ExprVar("x")));
    String opExpectedString = StrUtils.strjoinNL("(assign ((?x 1) (?y ?x))", "  (table unit))");
    check(assign, new TransformExtendCombine(), opExpectedString);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Op(org.apache.jena.sparql.algebra.Op) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Example 50 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project webofneeds by researchstudio-sat.

the class SparqlSelectFunction method addOrderBy.

/**
 * Use Query.ORDER_* for the direction value.
 *
 * @param varName
 * @param direction
 */
public SparqlSelectFunction<T> addOrderBy(String varName, int direction) {
    varName = Var.canonical(varName);
    SortCondition sc = new SortCondition(new ExprVar(varName), direction);
    addOrderBy(sc);
    return this;
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar)

Aggregations

ExprVar (org.apache.jena.sparql.expr.ExprVar)51 Expr (org.apache.jena.sparql.expr.Expr)34 Test (org.junit.Test)17 ContractTest (org.xenei.junit.contract.ContractTest)15 Var (org.apache.jena.sparql.core.Var)12 SortCondition (org.apache.jena.query.SortCondition)11 Node (org.apache.jena.graph.Node)9 Op (org.apache.jena.sparql.algebra.Op)7 Triple (org.apache.jena.graph.Triple)6 Query (org.apache.jena.query.Query)6 E_LessThan (org.apache.jena.sparql.expr.E_LessThan)5 E_Random (org.apache.jena.sparql.expr.E_Random)5 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)5 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)4 BasicPattern (org.apache.jena.sparql.core.BasicPattern)4 E_Multiply (org.apache.jena.sparql.expr.E_Multiply)4 ElementFilter (org.apache.jena.sparql.syntax.ElementFilter)4 ArrayList (java.util.ArrayList)3 E_Regex (org.apache.jena.sparql.expr.E_Regex)3 Random (java.util.Random)2