Refine search
private static long parseAsInteger(Node n) throws SQLException { if (n == null) throw new SQLException("Unable to marshal a null to an integer"); if (n.isLiteral()) { try { String lex = n.getLiteralLexicalForm(); if (lex.contains(".")) { return Long.parseLong(lex.substring(0, lex.indexOf('.'))); } else { return Long.parseLong(lex); } } catch (Exception e) { throw new SQLException("Unable to marshal an invalid numeric representation to an integer", e); } } else { throw new SQLException("Unable to marshal a non-literal to an integer"); } }
private static long parseAsInteger(Node n) throws SQLException { if (n == null) throw new SQLException("Unable to marshal a null to an integer"); if (n.isLiteral()) { try { String lex = n.getLiteralLexicalForm(); if (lex.contains(".")) { return Long.parseLong(lex.substring(0, lex.indexOf('.'))); } else { return Long.parseLong(lex); } } catch (Exception e) { throw new SQLException("Unable to marshal an invalid numeric representation to an integer", e); } } else { throw new SQLException("Unable to marshal a non-literal to an integer"); } }
private static String simpleLiteralOrXSDString(Node n) { if ( !n.isLiteral() ) return null ; if ( n.getLiteralDatatype() == null ) { if ( n.getLiteralLanguage().equals("") ) return n.getLiteralLexicalForm() ; } else if ( n.getLiteralDatatype().equals(XSDDatatype.XSDstring) ) return n.getLiteralLexicalForm() ; return null ; }
/** Get lexical for of anything that looks like a string literal. * Returns the string value of plain literal (simple literal * or lang string) or XSD string. */ public static String stringLiteral(Node literal) { if ( !literal.isLiteral() ) return null ; RDFDatatype dType = literal.getLiteralDatatype() ; String langTag = literal.getLiteralLanguage() ; // Language? if ( langTag != null && !langTag.equals("") ) return literal.getLiteralLexicalForm() ; if ( dType == null || dType.equals(XSDDatatype.XSDstring) ) return literal.getLiteralLexicalForm() ; return null ; }
private static Node fixupNode(Node node) { if ( node == null || node == Node.ANY ) return node ; // RDF says ... language tags should be canonicalized to lower case. if ( node.isLiteral() ) { String lang = node.getLiteralLanguage() ; if ( lang != null && ! lang.equals("") ) node = NodeFactory.createLiteral(node.getLiteralLexicalForm(), lang.toLowerCase(Locale.ROOT)) ; } return node ; }
private static Node fixupNode(Node node) { if ( node == null || node == Node.ANY ) return node ; // RDF says ... language tags should be canonicalized to lower case. if ( node.isLiteral() ) { String lang = node.getLiteralLanguage() ; if ( lang != null && ! lang.equals("") ) node = NodeFactory.createLiteral(node.getLiteralLexicalForm(), lang.toLowerCase(Locale.ROOT)) ; } return node ; }
public static boolean sameTerm(Node n1, Node n2) { if ( n1.equals(n2) ) return true ; if ( n1.isLiteral() && n2.isLiteral() ) { // But language tags are case insensitive. String lang1 = n1.getLiteralLanguage() ; String lang2 = n2.getLiteralLanguage() ; if ( !lang1.equals("") && lang1.equalsIgnoreCase(lang2) ) { // Two language tags, equal by case insensitivity. boolean b = n1.getLiteralLexicalForm().equals(n2.getLiteralLexicalForm()) ; if ( b ) return true ; } } return false ; }
/** * Return the lexical form of a literal node, error for other node types */ protected String getString(Node n, RuleContext context) { if (n.isLiteral()) { return n.getLiteralLexicalForm(); } else { throw new BuiltinException(this, context, getName() + " takes only literal arguments"); } }
/** * Return the lexical form of a literal node, error for other node types */ protected String getString(Node n, RuleContext context) { if (n.isLiteral()) { return n.getLiteralLexicalForm(); } else { throw new BuiltinException(this, context, getName() + " takes only literal arguments"); } }
protected Node stripSign(Node node) { if ( !node.isLiteral() ) return node ; String lex = node.getLiteralLexicalForm() ; String lang = node.getLiteralLanguage() ; RDFDatatype dt = node.getLiteralDatatype() ; if ( !lex.startsWith("-") && !lex.startsWith("+") ) throw new ARQInternalErrorException("Literal does not start with a sign: " + lex) ; lex = lex.substring(1) ; return NodeFactory.createLiteral(lex, lang, dt) ; }
private static Node fixupNode(Node node) { if (node == null || node == Node.ANY) return node; // RDF says ... language tags should be canonicalized to lower case. if (node.isLiteral()) { String lang = node.getLiteralLanguage(); if (lang != null && !lang.equals("")) node = NodeFactory.createLiteral(node.getLiteralLexicalForm(), lang.toLowerCase(Locale.ROOT), node.getLiteralDatatype()); } return node; }
public static boolean rdfTermEquals(Node n1, Node n2) { if ( n1.equals(n2) ) return true ; if ( n1.isLiteral() && n2.isLiteral() ) { // Two literals, may be sameTerm by language tag case insensitivity. String lang1 = n1.getLiteralLanguage() ; String lang2 = n2.getLiteralLanguage() ; if ( !lang1.equals("") && lang1.equalsIgnoreCase(lang2) ) { // Two language tags, equal by case insensitivity. boolean b = n1.getLiteralLexicalForm().equals(n2.getLiteralLexicalForm()) ; if ( b ) return true ; } // Two literals, different terms, different language tags. NodeValue.raise(new ExprEvalException("Mismatch in RDFterm-equals: " + n1 + ", " + n2)) ; } // One or both not a literal. return false ; }
private String getModelName( Statement s ) { Node o = s.getObject().asNode(); return o.isLiteral() ? o.getLiteralLexicalForm(): o.getURI(); }
private String getModelName( Statement s ) { Node o = s.getObject().asNode(); return o.isLiteral() ? o.getLiteralLexicalForm(): o.getURI(); }
@Override protected NodeValue exec(Node regexNode, FunctionEnv env) { if(regexNode == null || !regexNode.isLiteral()) { return NodeValue.makeString("Invalid argument to spif:checkRegexSyntax: " + regexNode); } else { String str = regexNode.getLiteralLexicalForm(); try { Pattern.compile(str); } catch(Exception ex) { return NodeValue.makeString(ex.getMessage()); } throw new ExprEvalException(); // OK } } }
@Override protected NodeValue exec(Node arg, FunctionEnv env) { if(arg == null || !arg.isLiteral()) { throw new ExprEvalException("Argument must be a (string) literal"); } return NodeValue.makeBoolean(LangTag.check(arg.getLiteralLexicalForm())); } }
@Override protected NodeValue exec(Node regexNode, FunctionEnv env) { if(regexNode == null || !regexNode.isLiteral()) { return NodeValue.makeString("Invalid argument to spif:checkRegexSyntax: " + regexNode); } else { String str = regexNode.getLiteralLexicalForm(); try { Pattern.compile(str); } catch(Exception ex) { return NodeValue.makeString(ex.getMessage()); } throw new ExprEvalException(); // OK } } }
@Override protected NodeValue exec(Node arg, FunctionEnv env) { if(arg == null || !arg.isLiteral()) { throw new ExprEvalException("Argument must be a (string) literal"); } return NodeValue.makeBoolean(LangTag.check(arg.getLiteralLexicalForm())); } }
public static boolean checkLiteral(Node node, ErrorHandler handler, long line, long col) { if ( !node.isLiteral() ) { handler.error("Not a literal: " + node, line, col) ; return false ; } return checkLiteral(node.getLiteralLexicalForm(), node.getLiteralLanguage(), node.getLiteralDatatype(), handler, line, col) ; }
public long asInteger() { if ( isNode() ) { if ( getNode().isLiteral() ) // Ignore typing. return Integer.parseInt(getNode().getLiteralLexicalForm()) ; } if ( isSymbol() ) return Integer.parseInt(getSymbol()) ; throw new ItemException("Not a literal or string: "+this) ; }