use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class TransformFilterDisjunction method explodeDisjunction.
/** Explode a expr into a list of disjunctions */
private static List<Expr> explodeDisjunction(List<Expr> exprList, Expr expr) {
if (!(expr instanceof E_LogicalOr)) {
exprList.add(expr);
return exprList;
}
E_LogicalOr exprOr = (E_LogicalOr) expr;
Expr e1 = exprOr.getArg1();
Expr e2 = exprOr.getArg2();
explodeDisjunction(exprList, e1);
explodeDisjunction(exprList, e2);
return exprList;
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class TransformFilterDisjunction method expandDisjunction.
// Todo:
// 1 - convert TransformEqualityFilter to use ExprLib for testing.
// 2 - Scan for safe equality filters in disjunction.
public static Op expandDisjunction(Expr expr, Op subOp) {
// if ( !( expr instanceof E_LogicalOr ) )
// return null ;
List<Expr> exprList = explodeDisjunction(new ArrayList<Expr>(), expr);
// All disjunctions - some can be done efficiently via assignments, some can not.
// Really should only do if every disjunction can turned into a assign-grounded pattern
// otherwise the full is done anyway.
List<Expr> exprList2 = null;
Op op = null;
for (Expr e : exprList) {
Op op2 = TransformFilterEquality.processFilter(e, subOp);
if (op2 == null) {
// Not done.
if (exprList2 == null)
exprList2 = new ArrayList<>();
exprList2.add(e);
//continue ;
// Can't do one so don't do any as the original pattern is still executed.
}
op = OpDisjunction.create(op, op2);
}
if (exprList2 != null && !exprList2.isEmpty()) {
// These are left as disjunctions.
Expr eOther = null;
for (Expr e : exprList2) {
if (eOther == null)
eOther = e;
else
eOther = new E_LogicalOr(eOther, e);
}
Op opOther = OpFilter.filter(eOther, subOp);
op = OpDisjunction.create(op, opOther);
}
return op;
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class SyntaxVarScope method checkExprVarUse.
private static void checkExprVarUse(Query query) {
if (query.hasGroupBy()) {
VarExprList groupKey = query.getGroupBy();
// Copy - we need to add variables
// SELECT (count(*) AS ?C) (?C+1 as ?D)
List<Var> inScopeVars = new ArrayList<>(groupKey.getVars());
VarExprList exprList = query.getProject();
for (Var v : exprList.getVars()) {
// In scope?
Expr e = exprList.getExpr(v);
if (e == null) {
if (!inScopeVars.contains(v)) {
throw new QueryParseException("Non-group key variable in SELECT: " + v, -1, -1);
}
} else {
Set<Var> eVars = e.getVarsMentioned();
for (Var v2 : eVars) {
if (!inScopeVars.contains(v2)) {
throw new QueryParseException("Non-group key variable in SELECT: " + v2 + " in expression " + e, -1, -1);
}
}
}
inScopeVars.add(v);
}
}
}
use of org.apache.jena.sparql.expr.Expr 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());
}
use of org.apache.jena.sparql.expr.Expr 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());
}
Aggregations