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); }
@Override public Node create(Node currentGraph, Token token) { // Dispatches to the underlying operation long line = token.getLine(); long col = token.getColumn(); String str = token.getImage(); switch (token.getType()) { case BNODE: return createBlankNode(currentGraph, str, line, col); case IRI: return createURI(str, line, col); case PREFIXED_NAME: { String prefix = str; String suffix = token.getImage2(); String expansion = expandPrefixedName(prefix, suffix, token); return createURI(expansion, line, col); } case DECIMAL: return createTypedLiteral(str, XSDDatatype.XSDdecimal, line, col); case DOUBLE: return createTypedLiteral(str, XSDDatatype.XSDdouble, line, col); case INTEGER: return createTypedLiteral(str, XSDDatatype.XSDinteger, line, col); case LITERAL_DT: { Token tokenDT = token.getSubToken(); String uriStr; switch (tokenDT.getType()) { case IRI: uriStr = tokenDT.getImage(); break; case PREFIXED_NAME: { String prefix = tokenDT.getImage(); String suffix = tokenDT.getImage2(); uriStr = expandPrefixedName(prefix, suffix, tokenDT); break; } default: throw new RiotException("Expected IRI for datatype: " + token); } uriStr = resolveIRI(uriStr, tokenDT.getLine(), tokenDT.getColumn()); RDFDatatype dt = Node.getType(uriStr); return createTypedLiteral(str, dt, line, col); } case LITERAL_LANG: return createLangLiteral(str, token.getImage2(), line, col); case STRING: case STRING1: case STRING2: case LONG_STRING1: case LONG_STRING2: return createPlainLiteral(str, line, col); default: { Node x = createNodeFromToken(currentGraph, token, line, col); if (x != null) return x; errorHandler.fatal("Not a valid token for an RDF term: " + token, line, col); return null; } } }