Refine search
public static RdfTermType deriveType(Node node) { if(node.isURI()) { return RdfTermType.URI; } else if(node.isLiteral()) { return RdfTermType.LITERAL; } else if(node.isBlank()) { throw new RuntimeException("Decide on what to return here."); //return Type.URI; } else { return RdfTermType.UNKNOWN; } }
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"); } }
protected void output(Writer w, Node n, NodeToLabelMap bnodes) throws IOException { //String str = FmtUtils.stringForNode(n) ; String str = "?" ; if ( n.isLiteral() ) str = n.getLiteralLexicalForm() ; else if ( n.isURI() ) str = n.getURI() ; else if ( n.isBlank() ) str = bnodes.asString(n) ; str = csvSafe(str) ; w.write(str) ; }
public static String compileFilter(Node node, String columnName) { if (node.isURI()) { return columnName + " = <" + node.getURI() + ">"; } else if (node.isLiteral()) { String result = "str(" + columnName + ") = '" + node.getLiteralLexicalForm() + "'"; if (!node.getLiteralLanguage().isEmpty()) { result += " && langMatches(lang(" + columnName + "), '" + node.getLiteralLanguage() + "')"; } else if (node.getLiteralDatatypeURI() != null) { result += " && datatype(" + columnName + ") = <" + node.getLiteralDatatypeURI() + ">"; } return result; } else { throw new RuntimeException( "Should never come here - maybe a blank node of evilness?"); } }
public SerialisableTriple(Triple triple){ this.triple = triple; Node _sbj = this.triple.getSubject(); if (_sbj.isBlank()) isSubjectBlank = true; this.subject = _sbj.toString(); this.predicate = this.triple.getPredicate().toString(); Node _obj = this.triple.getObject(); if (_obj.isBlank()) isObjectBlank = true; this.object = _obj.toString(); if (_obj.isLiteral()) { isObjectLiteral = true; objectDataType = _obj.getLiteralDatatype(); objectDT = _obj.getLiteralDatatypeURI(); objectLang = _obj.getLiteralLanguage(); object = _obj.getLiteralLexicalForm(); } }
public static RdfTermType getNodeType(Node node) { if(node == null) { return RdfTermType.UNKNOWN; } else if(node.isURI()) { return RdfTermType.URI; } else if(node.isLiteral()) { return RdfTermType.LITERAL; } else if(node.isBlank()) { return RdfTermType.BLANK; } else { throw new RuntimeException("Should not happen"); } }
/** * Return the appropriate lexical form of a node */ protected String lex(Node n, RuleContext context) { if (n.isBlank()) { return n.getBlankNodeLabel(); } else if (n.isURI()) { return n.getURI(); } else if (n.isLiteral()) { return n.getLiteralLexicalForm(); } else { throw new BuiltinException(this, context, "Illegal node type: " + n); } }
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"); } }
public static RdfTermPattern _deriveRegex(NodeValue expr) { Node node = expr.asNode(); String value = null; if(node.isLiteral()) { value = node.getLiteralLexicalForm(); } else if(node.isURI()) { value = node.getURI(); } else { throw new RuntimeException("Should not happen"); } String datatype = null; if(node.isLiteral()) { datatype = node.getLiteralDatatypeURI(); } PatternPro a = value == null ? null : new PatternPro(RegexUtils.escape(value)); PatternPro b = datatype == null ? null : new PatternPro(RegexUtils.escape(datatype)); return new RdfTermPattern(a, b); }
static public NodeType lookup(Node n) { if ( n.isURI() ) return URI ; if ( n.isBlank() ) return BNODE ; if ( n.isLiteral() ) { return LITERAL ; // if ( n.getLiteralDatatypeURI() == null ) // // String - plain literal // return STRING ; // if ( n.getLiteralDatatype() == XSDDatatype.XSDstring ) // return XSDSTRING ; // if ( n.getLiteralDatatype() == XSDDatatype.XSDinteger ) // return INTEGER ; // if ( n.getLiteralDatatype() == XSDDatatype.XSDdouble ) // return DOUBLE ; // if ( n.getLiteralDatatype() == XSDDatatype.XSDdateTime ) // return DATETIME ; } return OTHER ; }
/** * Return the appropriate lexical form of a node */ protected String lex(Node n, RuleContext context) { if (n.isBlank()) { return n.getBlankNodeLabel(); } else if (n.isURI()) { return n.getURI(); } else if (n.isLiteral()) { return n.getLiteralLexicalForm(); } else { throw new BuiltinException(this, context, "Illegal node type: " + n); } }
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 ; }
@Override protected NodeValue exec(Node literalNode, Node datatypeNode, FunctionEnv env) { if(literalNode == null || !literalNode.isLiteral()) { throw new ExprEvalException(); } String lex = literalNode.getLiteralLexicalForm(); if(!datatypeNode.isURI()) { throw new ExprEvalException(); } RDFDatatype datatype = TypeMapper.getInstance().getTypeByName(datatypeNode.getURI()); if(datatype == null) { return NodeValue.TRUE; } else { boolean valid = datatype.isValid(lex); return NodeValue.makeBoolean(valid); } } }
protected static Expr buildFunctionCall(ItemList list) { Item head = list.get(0) ; Node node = head.getNode() ; if ( node.isBlank() ) BuilderLib.broken(head, "Blank node for function call!") ; if ( node.isLiteral() ) BuilderLib.broken(head, "Literal node for function call!") ; ExprList args = buildExprListUntagged(list, 1) ; // Args return new E_Function(node.getURI(), args) ; }