private boolean deriveRestrictionEquals(Expr a, Expr b) { if(a.isVariable() && b.isConstant()) { RestrictionImpl r = getOrCreateRestriction(a.asVar()); r.stateNode(b.getConstant().asNode()); return true; } return false; }
public boolean equals(ExprList other, boolean bySyntax) { if ( this == other ) return true ; if (expressions.size() != other.expressions.size()) return false; for ( int i = 0 ; i < expressions.size() ; i++ ) { Expr e1 = expressions.get(i) ; Expr e2 = other.expressions.get(i) ; if ( ! e1.equals(e2, bySyntax) ) return false ; } return true ; }
public static RdfTermType deriveType(Expr expr) { RdfTermType result = null; if(expr.isConstant()) { result = deriveType(expr.getConstant().asNode()); } else if(expr.isFunction()) { result = deriveType(expr.getFunction()); } return result; } }
private static GraphTraversal<?, ?> transform(final E_Equals expression) { final Object value = expression.getArg2().getConstant().getNode().getLiteralValue(); return __.as(expression.getArg1().getVarName()).is(P.eq(value)); }
public static int classify(Expr e) { int result = e.isConstant() ? 0 : e.isVariable() ? 1 : e.isFunction() ? 2 : 3; return result; }
public static String getColumnName(Expr expr) { String result; if(expr.isVariable()) { result = expr.asVar().getName(); } else { throw new RuntimeException("plainLiteral: first argument must be a column reference"); } return result; }
static void testDouble(String exprString, Node result, double delta) { Expr expr = ExprUtils.parse(exprString, pmap); NodeValue actual = expr.eval(null, new FunctionEnvBase()); NodeValue expected = NodeValue.makeNode(result); // Note that we don't test lexical form because we can get mismatches // between how things like doubles are expressed if (NodeValue.sameAs(expected, actual)) return; testDouble(exprString, expected.getDouble(), delta); ; }
public static String toString(Entry<Var, Expr> e) { Var v = e.getKey(); Expr x = e.getValue(); String result = x.isVariable() && x.asVar().equals(v) ? "" + v : "(" + x + " AS " + v + ")"; return result; }
if(expr != null && (!expr.isVariable() || binding.contains(expr.asVar()))) { NodeValue x = expr.eval(binding, env); if(x != null) { String paramName; paramName = "arg" + (i + 1); bindings.add(paramName, model.asRDFNode(x.asNode())); if(cachable) { paramsForCache[i] = x.asNode(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); IndentedWriter iOut = new IndentedWriter(bos); ExprUtils.fmtSPARQL(iOut, expr, new SerializationContext(model)); iOut.flush(); sb.append(bos.toString()); sb.append(FmtUtils.stringForNode(result.asNode(), model));
@Override public void startElement(ElementBind el) { if(preBoundVars.contains(el.getVar().getVarName())) { if(SH.valueVar.getVarName().equals(el.getVar().getVarName()) && el.getExpr().isVariable() && el.getExpr().asVar().equals(SH.thisVar)) { // Ignore clauses injected by engine } else { results.add("Query must not reassign the pre-bound variable " + el.getVar() + " in a BIND clause"); } } }
public static String getString(Expr expr) { String result = null; if(expr.isConstant()) { NodeValue nv = expr.getConstant(); if(nv.isString()) { result = nv.getString(); } } return result; }
public static String derivePrefix(Expr expr) { String result; if(expr.isFunction()) { result = derivePrefix(expr.getFunction()); } else if(expr.isConstant()) { result = derivePrefix(expr.getConstant().getNode()); } else { result = null; } return result; }
private static void test_exprSprintf_tz_possibilites(String nodeStr, String... possible) { String exprStr = "afn:sprintf('%1$tm %1$te,%1$tY', "+NodeValue.makeDateTime(nodeStr).toString()+")" ; Expr expr = ExprUtils.parse(exprStr) ; NodeValue r = expr.eval(null, LibTestExpr.createTest()) ; assertTrue(r.isString()) ; String s = r.getString() ; // Timezones! The locale data can be -1, 0, +1 from the Z day. boolean b = false ; for (String poss : possible ) { if ( poss.equals(s) ) b = true ; } assertTrue(b) ; }
public static E_RdfTerm expandRdfTerm(Expr expr) { E_RdfTerm result = null; if(expr.isFunction()) { result = expandRdfTerm(expr.getFunction()); } /* else if(expr.isConstant()) { result = expandConstant(expr); }*/ return result; }
public static Optional<String> getIriOrString(Expr expr) { //String result = expr.isConstant() ? expr.getConstant() Optional<String> result = Optional.of(expr) .map(e -> e.isConstant() ? e.getConstant() : null) .map(e -> e.asString()); return result; }
@Override public void visit(NodeValue nv) { if ( ! target.isConstant() ) throw new NoExprMatch("Not a NodeValue") ; if ( ! nv.equals(target.getConstant()) ) throw new NoExprMatch("Different value: "+nv+" & "+target.getConstant()) ; }
public static String derivePrefixConcat(ExprFunction concat) { // TODO If all arguments are constant, we could infer a constant constraint String prefix = ""; for(Expr arg : concat.getArgs()) { if(arg.isConstant()) { prefix += arg.getConstant().asUnquotedString(); } else { break; } } return prefix; }
@Override public boolean equalTo(Element el2, NodeIsomorphismMap isoMap) { if ( ! ( el2 instanceof ElementAssign ) ) return false ; ElementAssign f2 = (ElementAssign)el2 ; if ( ! this.getVar().equals(f2.getVar() )) return false ; if ( ! this.getExpr().equals(f2.getExpr()) ) return false ; return true ; }