use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class NodeTransformLib method transformVars.
/** Apply the NodeTransform to the variables of a VarExprList. */
public static VarExprList transformVars(NodeTransform transform, VarExprList varExprList) {
VarExprList varExprList2 = new VarExprList();
boolean changed = false;
// Just variables.
for (Var v : varExprList.getVars()) {
Expr expr = varExprList.getExpr(v);
Var v2 = (Var) transform.apply(v);
if (!Objects.equals(v, v2))
changed = true;
varExprList2.add(v2, expr);
}
if (!changed)
return varExprList;
return varExprList2;
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class NodeTransformLib method transform.
public static ExprList transform(NodeTransform nodeTransform, ExprList exprList) {
ExprList exprList2 = new ExprList();
boolean changed = false;
for (Expr expr : exprList) {
Expr expr2 = transform(nodeTransform, expr);
if (expr != expr2)
changed = true;
exprList2.add(expr2);
}
if (!changed)
return exprList;
return exprList2;
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class SyntaxVarScope method fmtExprList.
private static String fmtExprList(VarExprList exprList) {
StringBuilder sb = new StringBuilder();
boolean first = true;
for (Var v : exprList.getVars()) {
Expr e = exprList.getExpr(v);
if (!first) {
sb.append(" ");
}
first = false;
sb.append("(").append(e).append(" AS ").append(v).append(")");
}
return sb.toString();
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class QueryTransformOps method transformVarExprList.
// ** Mutates the VarExprList
private static void transformVarExprList(VarExprList varExprList, ExprTransform exprTransform) {
Map<Var, Expr> map = varExprList.getExprs();
for (Var v : varExprList.getVars()) {
Expr e = varExprList.getExpr(v);
ExprVar ev = new ExprVar(v);
Expr ev2 = exprTransform.transform(ev);
if (ev != ev2) {
if (e != null)
throw new ARQException("Can't substitute " + v + " because it's used as an AS variable");
if (ev2.isConstant() || ev2.isVariable()) {
// Convert to (substitute value AS ?var)
map.put(v, ev2);
continue;
} else
throw new ARQException("Can't substitute " + v + " because it's not a simple value: " + ev2);
}
if (e == null)
continue;
// Didn't change the variable.
Expr e2 = ExprTransformer.transform(exprTransform, e);
if (e != e2)
// replace
map.put(v, e2);
}
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class TransformElementLib method apply.
public static Node apply(Node n, ExprTransform exprTransform) {
if (exprTransform == null)
return n;
Expr e = null;
if (Var.isVar(n)) {
Var v = Var.alloc(n);
ExprVar expr = new ExprVar(v);
e = exprTransform.transform(expr);
} else {
NodeValue nv = NodeValue.makeNode(n);
e = exprTransform.transform(nv);
}
if (e instanceof ExprVar)
return ((ExprVar) e).asVar();
if (e instanceof NodeValue)
return ((NodeValue) e).asNode();
throw new InternalErrorException("Managed to turn a node " + n + " into " + e);
}
Aggregations