public static NodeValue dtGetDay(NodeValue nv) { if ( nv.isDateTime() || nv.isDate() || nv.isGMonthDay() || nv.isGDay() ) { DateTimeStruct dts = parseAnyDT(nv) ; return NodeValue.makeNode(dts.day, XSDDatatype.XSDinteger) ; } throw new ExprEvalException("Not a month datatype") ; }
/** * {@inheritDoc} */ @Override public NodeValue exec(NodeValue v) { return NodeValue.makeString(SemanticElement.removePrefix(v.asNode())); }
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) ; }
@Override public NodeValue eval(NodeValue x, NodeValue y) { int r = NodeValue.compare(x, y) ; return NodeValue.booleanReturn( r == Expr.CMP_LESS || r == Expr.CMP_EQUAL ) ; }
@Override public NodeValue eval(NodeValue x, NodeValue y) { // Note: notSameValueAs means "known to be different" // sameValueAs means "know to be the same value" // so they are not opposites boolean b = NodeValue.notSameAs(x, y) ; return NodeValue.booleanReturn(b) ; }
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) ; }
@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) { // Evaluation only happens as part of copySubstitute. // Proper evaluation is a special form as above. if ( ! x.isBoolean() ) throw new ExprEvalException("Not a boolean: "+x) ; if ( ! y.isBoolean() ) throw new ExprEvalException("Not a boolean: "+y) ; boolean boolX = x.getBoolean() ; boolean boolY = y.getBoolean() ; return NodeValue.makeBoolean( boolX && boolY ) ; }
public static NodeValue javaSubstring(NodeValue nvString, NodeValue nvStart, NodeValue nvFinish) { try { String string = nvString.getString() ; int start = nvStart.getInteger().intValue() ; if ( nvFinish == null ) return NodeValue.makeString(string.substring(start)) ; int finish = nvFinish.getInteger().intValue() ; return NodeValue.makeString(string.substring(start, finish)) ; } catch (IndexOutOfBoundsException ex) { throw new ExprEvalException("IndexOutOfBounds", ex) ; } }
public static NodeValue makeNodeString(String string) { NodeValue nv = makeNode(string, null, (String)null) ; return nv ; }
public static NodeValue strEndsWith(NodeValue string, NodeValue match) { check2("strEnds", string, match) ; String lex1 = string.asNode().getLiteralLexicalForm() ; String lex2 = match.asNode().getLiteralLexicalForm() ; return NodeValue.booleanReturn(lex1.endsWith(lex2)) ; }
public static String str(Node node) { if ( node.isLiteral() ) return node.getLiteral().getLexicalForm() ; if ( node.isURI() ) return node.getURI() ; // if ( node.isBlank() ) return node.getBlankNodeId().getLabelString() ; // if ( node.isBlank() ) return "" ; if ( node.isBlank() ) NodeValue.raise(new ExprTypeException("Blank node: "+node)) ; NodeValue.raise(new ExprEvalException("Not a string: "+node)) ; return "[undef]" ; }
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 fnConcat(List<NodeValue> args) { StringBuilder sb = new StringBuilder() ; for ( NodeValue arg : args ) { String x = arg.asString() ; sb.append(x) ; } return NodeValue.makeString(sb.toString()) ; }
@Override public NodeValue exec(NodeValue namespace, NodeValue label) { String argument1 = namespace.getString(); String argument2 = label.getString(); String[] argument2Splitted = argument2.split(" "); String localName = argument2Splitted[0].substring(0, 1).toLowerCase() + argument2Splitted[0].substring(1, argument2Splitted[0].length()); for (int i = 1; i < argument2Splitted.length; i++) { localName += argument2Splitted[i].substring(0, 1).toUpperCase() + argument2Splitted[i].substring(1, argument2Splitted[i].length()); } String newString = argument1 + localName; return NodeValue.makeString(newString); }
@Override public NodeValue eval(FunctionEnv env) { return NodeValue.makeString(ARQ.NAME+" "+ARQ.VERSION) ; } }
@Override public void accumulateDistinct(NodeValue nv, Binding binding, FunctionEnv functionEnv) { String str = nv.asString() ; if ( ! first ) stringSoFar.append(separator) ; stringSoFar.append(str) ; first = false ; }