@Override public NodeValue eval(List<NodeValue> args) { NodeValue v = args.get(0) ; NodeValue vPattern = args.get(1) ; NodeValue vFlags = ( args.size() == 2 ? null : args.get(2) ) ; if ( ! v.isString() ) throw new ExprEvalException("REGEX: "+v+" is not a string") ; RegexEngine regex = regexEngine ; if ( regex == null ) regex = makeRegexEngine(vPattern, vFlags) ; boolean b = regex.match(v.getString()) ; return b ? NodeValue.TRUE : NodeValue.FALSE ; }
private static boolean isString(Expr expr) { return expr.isConstant() && expr.getConstant().isString() ; }
public static RegexEngine makeRegexEngine(NodeValue vPattern, NodeValue vFlags) { if ( ! vPattern.isString() ) throw new ExprException("REGEX: Pattern is not a string: "+vPattern) ; if ( vFlags != null && ! vFlags.isString() ) throw new ExprException("REGEX: Pattern flags are not a string: "+vFlags) ; String s = (vFlags==null)?null:vFlags.getString() ; return makeRegexEngine(vPattern.getString(), s) ; }
public static RegexEngine makeRegexEngine(NodeValue vPattern, NodeValue vFlags) { if ( ! vPattern.isString() ) throw new ExprException("REGEX: Pattern is not a string: "+vPattern) ; if ( vFlags != null && ! vFlags.isString() ) throw new ExprException("REGEX: Pattern flags are not a string: "+vFlags) ; String s = (vFlags==null)?null:vFlags.getString() ; return makeRegexEngine(vPattern.getString(), s) ; }
public static NodeValue strLang(NodeValue v1, NodeValue v2) { if ( ! v1.isString() ) throw new ExprEvalException("Not a string (arg 1): "+v1) ; if ( ! v2.isString() ) throw new ExprEvalException("Not a string (arg 2): "+v2) ; String lex = v1.asString() ; String lang = v2.asString() ; // Check? Node n = Node.createLiteral(lex, lang, null) ; return NodeValue.makeNode(n) ; }
public static NodeValue strLang(NodeValue v1, NodeValue v2) { if ( !v1.isString() ) throw new ExprEvalException("Not a string (arg 1): " + v1) ; if ( !v2.isString() ) throw new ExprEvalException("Not a string (arg 2): " + v2) ; String lex = v1.asString() ; String lang = v2.asString() ; // Check? Node n = NodeFactory.createLiteral(lex, lang, null) ; return NodeValue.makeNode(n) ; }
@Override protected NodeValue cast(String s, NodeValue nv, XSDDatatype castType) { // Plain cast. if ( nv.isString() || NodeUtils.hasLang(nv.asNode()) ) return super.cast(s, nv, castType) ; return XSDFuncOp.dateTimeCast(nv, castType) ; } }
@Override protected NodeValue cast(String s, NodeValue nv, XSDDatatype castType) { // Plain cast. if ( nv.isString() || NodeUtils.hasLang(nv.asNode()) ) return super.cast(s, nv, castType) ; return XSDFuncOp.dateTimeCast(nv, castType) ; } }
@Override public NodeValue eval(NodeValue x, NodeValue y) { if ( ARQ.isStrictMode() ) return XSDFuncOp.add(x, y) ; if ( true ) { if ( x.isString() && y.isString() ) return NodeValue.makeString(x.asString()+y.asString()) ; if ( ! x.isNumber() || ! y.isNumber() ) throw new ExprEvalTypeException("Operator '+' requires two numbers or two strings: got: "+x+" and "+y) ; } return XSDFuncOp.add(x, y) ; }
@Override public NodeValue exec(NodeValue v) { if ( ! v.isString() ) { Log.warn(this, "date: argument not a string: "+v) ; throw new ExprEvalException("date: argument not a string: "+v) ; } String lexicalForm = v.getString() ; // Quite picky about format if ( ! lexicalForm.matches("\\d{4}-\\d{2}-\\d{2}") ) { Log.warn(this, "date: argument not in date format: "+v) ; throw new ExprEvalException("date: argument not in date format: "+v) ; } lexicalForm=lexicalForm+"T00:00:00Z" ; NodeValue nv = NodeValue.makeNode(lexicalForm, XSDDatatype.XSDdateTime) ; return nv ; }
public static boolean booleanEffectiveValue(NodeValue nv) // F&O fn:boolean { // Apply the "boolean effective value" rules //boolean: value of the boolean (strictly, if derived from xsd:boolean) //string: length(string) > 0 //numeric: number != Nan && number != 0 // http://www.w3.org/TR/xquery/#dt-ebv if ( nv.isBoolean() ) return nv.getBoolean() ; if ( nv.isString() ) return nv.getString().length() > 0 ; if ( nv.isInteger() ) return ! nv.getInteger().equals(NodeValue.IntegerZERO) ; if ( nv.isDecimal() ) return ! nv.getDecimal().equals(NodeValue.DecimalZERO) ; if ( nv.isDouble() ) return nv.getDouble() != 0.0 ; NodeValue.raise(new ExprEvalException("Not a boolean effective value (wrong type): "+nv)) ; // Does not return return false ; }
private void init(Expr pattern, Expr flags) { if ( pattern.isConstant() && pattern.getConstant().isString() && ( flags==null || flags.isConstant() ) ) regexEngine = makeRegexEngine(pattern.getConstant(), (flags==null)?null:flags.getConstant()) ; }
private void init(Expr pattern, Expr flags) { if ( pattern.isConstant() && pattern.getConstant().isString() && ( flags==null || flags.isConstant() ) ) regexEngine = makeRegexEngine(pattern.getConstant(), (flags==null)?null:flags.getConstant()) ; }
public E_StrReplace(Expr expr1, Expr expr2, Expr expr3, Expr expr4) { super(symbol, expr1, expr2, expr3, expr4) ; if ( isString(expr2) && (expr4 == null || isString(expr4) ) ) { int flags = 0 ; if ( expr4 != null && expr4.isConstant() && expr4.getConstant().isString() ) flags = RegexJava.makeMask(expr4.getConstant().getString()) ; pattern = Pattern.compile(expr2.getConstant().getString(), flags) ; } }
@Override public NodeValue eval(NodeValue x, NodeValue y) { if ( ! x.isString() ) throw new ExprEvalException("cast: arg 2 is not a string: "+x) ; if ( ! y.isIRI() ) throw new ExprEvalException("cast: arg 2 is not a URI: "+y) ; String lex = x.getString() ; y.asNode().getURI() ; throw new ARQNotImplemented() ; }
@Override public NodeValue eval(NodeValue x, NodeValue y) { if ( ! x.isString() ) throw new ExprEvalException("cast: arg 2 is not a string: "+x) ; if ( ! y.isIRI() ) throw new ExprEvalException("cast: arg 2 is not a URI: "+y) ; String lex = x.getString() ; y.asNode().getURI() ; throw new ARQNotImplemented() ; }
public static NodeValue strDatatype(NodeValue v1, NodeValue v2) { if ( !v1.isString() ) throw new ExprEvalException("Not a string (arg 1): " + v1) ; if ( !v2.isIRI() ) throw new ExprEvalException("Not an IRI (arg 2): " + v2) ; String lex = v1.asString() ; Node dt = v2.asNode() ; // Check? Node n = NodeFactory.createLiteral(lex, null, NodeFactory.getType(dt.getURI())) ; return NodeValue.makeNode(n) ; }
public static NodeValue strDatatype(NodeValue v1, NodeValue v2) { if ( ! v1.isString() ) throw new ExprEvalException("Not a string (arg 1): "+v1) ; if ( ! v2.isIRI() ) throw new ExprEvalException("Not an IRI (arg 2): "+v2) ; String lex = v1.asString() ; Node dt = v2.asNode() ; // Check? Node n = Node.createLiteral(lex, null, Node.getType(dt.getURI())) ; return NodeValue.makeNode(n) ; }
private static ValueSpaceClassification classifyValueSpace(NodeValue nv) { if ( nv.isNumber() ) return VSPACE_NUM ; if ( nv.isDateTime() ) return VSPACE_DATETIME ; if ( nv.isDate() ) return VSPACE_DATE ; if ( nv.isTime() ) return VSPACE_TIME ; if ( nv.isDuration() ) return VSPACE_DURATION ; if ( nv.isGYear() ) return VSPACE_G_YEAR ; if ( nv.isGYearMonth() ) return VSPACE_G_YEARMONTH ; if ( nv.isGMonth() ) return VSPACE_G_MONTH ; if ( nv.isGMonthDay() ) return VSPACE_G_MONTHDAY ; if ( nv.isGDay() ) return VSPACE_G_DAY ; if ( VALUE_EXTENSIONS && nv.isDate() ) return VSPACE_DATE ; if ( nv.isString()) return VSPACE_STRING ; if ( nv.isBoolean()) return VSPACE_BOOLEAN ; if ( ! nv.isLiteral() ) return VSPACE_NODE ; if ( VALUE_EXTENSIONS && nv.getNode() != null && nv.getNode().isLiteral() && ! nv.getNode().getLiteralLanguage().equals("") ) return VSPACE_LANG ; return VSPACE_UNKNOWN ; }
private static ValueSpaceClassification classifyValueSpace(NodeValue nv) { if ( nv.isNumber() ) return VSPACE_NUM ; if ( nv.isDateTime() ) return VSPACE_DATETIME ; if ( nv.isDate() ) return VSPACE_DATE ; if ( nv.isTime() ) return VSPACE_TIME ; if ( nv.isDuration() ) return VSPACE_DURATION ; if ( nv.isGYear() ) return VSPACE_G_YEAR ; if ( nv.isGYearMonth() ) return VSPACE_G_YEARMONTH ; if ( nv.isGMonth() ) return VSPACE_G_MONTH ; if ( nv.isGMonthDay() ) return VSPACE_G_MONTHDAY ; if ( nv.isGDay() ) return VSPACE_G_DAY ; if ( VALUE_EXTENSIONS && nv.isDate() ) return VSPACE_DATE ; if ( nv.isString()) return VSPACE_STRING ; if ( nv.isBoolean()) return VSPACE_BOOLEAN ; if ( ! nv.isLiteral() ) return VSPACE_NODE ; if ( VALUE_EXTENSIONS && nv.getNode() != null && nv.getNode().isLiteral() && ! nv.getNode().getLiteralLanguage().equals("") ) return VSPACE_LANG ; return VSPACE_UNKNOWN ; }