public static boolean hasLang(Node node) { if ( ! node.isLiteral() ) return false ; String x = node.getLiteralLanguage() ; if ( x == null ) return false ; if ( x.equals("") ) return false ; return true ; }
@Override public Resource wrapAsResource( Node n ) { if (n.isLiteral()) throw new UnsupportedOperationException( "literal cannot be converted to Resource" ); return this.getNodeAs( n, Resource.class ); }
protected final String stringForNode(Node n, SerializationContext context) { String str = FmtUtils.stringForNode(n, context); if (n.isLiteral() && str.contains("'")) { // Should escape ' to avoid a possible injection vulnerability str = str.replace("'", "\\'"); } return str; }
@Override public URI getLiteralType(Node n) { if(n.isLiteral()){ return toLiteralTypeURI(n.getLiteralDatatypeURI()); } else { throw new IllegalArgumentException("The parsed Node is not a Literal"); } }
@Override public EnhNode wrap(Node n, EnhGraph eg) { if (!n.isLiteral()) throw new LiteralRequiredException( n ); return new LiteralImpl(n,eg); } };
/** Answer true iff this triple can be compared for sameValueAs by .equals(), ie, it is a concrete triple with a non-literal object. */ protected final boolean isSafeForEquality( Triple t ) { return t.isConcrete() && !t.getObject().isLiteral(); } }
protected static boolean equalsObjectOK( Triple t ) { Node o = t.getObject(); return o.isLiteral() ? o.getLiteralDatatype() == null : true; }
/** create an RDF node which might be a literal, or not. */ public static RDFNode createObject( Node n, EnhGraph g ) { return n.isLiteral() ? (RDFNode) new LiteralImpl( n, g ) : new ResourceImpl( n, g ); }
@Override public String stringValue(Node node) { if(node.isLiteral()){ //we do not want '"example"@en' but 'example' return node.getLiteralLexicalForm(); } else { return node.toString(); } }
@Override public String stringValue(Node node) { if(node.isLiteral()){ //we do not want '"example"@en' but 'example' return node.getLiteralLexicalForm(); } else { return node.toString(); } }
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 Node.createLiteral(lex, lang, dt) ; }
/** * 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"); } }
@Override public EnhNode wrap(Node n,EnhGraph eg) { if ( n.isURI() || n.isBlank() ) return new ResourceImpl(n,eg); if ( n.isLiteral() ) return new LiteralImpl(n,eg); return null; } };
private String getModelName( Statement s ) { Node o = s.getObject().asNode(); return o.isLiteral() ? o.getLiteralLexicalForm(): o.getURI(); }
public static String lang(Node node) { if ( !node.isLiteral() ) NodeValue.raise(new ExprTypeException("lang: Not a literal: " + FmtUtils.stringForNode(node))) ; String s = node.getLiteralLanguage() ; if ( s == null ) s = "" ; return s ; }
public double getDouble() { if ( ! isNode() ) throw new ItemException("Not a node, can't be a double: "+this) ; if ( ! getNode().isLiteral() ) throw new ItemException("Not a literal, can't be a double: "+this) ; return ((Number)(getNode().getLiteralValue())).doubleValue() ; }
public int getInt() { if ( ! isNode() ) throw new ItemException("Not a node, can't be an integer: "+this) ; if ( ! getNode().isLiteral() ) throw new ItemException("Not a literal, can't be a integer: "+this) ; return ((Number)(getNode().getLiteralValue())).intValue() ; }
public int getLong() { if ( ! isNode() ) throw new ItemException("Not a node, can't be an integer: "+this) ; if ( ! getNode().isLiteral() ) throw new ItemException("Not a literal, can't be a integer: "+this) ; return ((Number)(getNode().getLiteralValue())).intValue() ; }
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) ; }
@Override protected void check(Quad quad) { if ( Var.isVar(quad.getGraph()) || Var.isVar(quad.getSubject()) || Var.isVar(quad.getPredicate()) || Var.isVar(quad.getObject())) throw new QueryParseException("Variables not permitted in data quad", -1, -1) ; if ( quad.getSubject().isLiteral() ) throw new QueryParseException("Literals not allowed as subjects in quad data", -1, -1) ; } }