Refine search
private void output(Writer w, Node n) 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 = n.getBlankNodeLabel() ; str = csvSafe(str) ; w.write(str) ; }
@Override public String stringValue(Node node) { if(node.isLiteral()){ //we do not want '"example"@en' but 'example' return node.getLiteralLexicalForm(); } else { return node.toString(); } }
public static void addNamespace(Set<String> namespaces, Node n) { if (n.isURI()) namespaces.add(n.getNameSpace()); if (n.isLiteral()) { String uri = n.getLiteralDatatypeURI(); if (uri != null) namespaces.add( NsUtils.getNameSpace( uri ) ); } }
int nodeType() { return innerNode.isURI() ? URI : innerNode.getLiteralDatatypeURI()!=null ? GENERAL_LITERAL : STRING; }
public static Any any(RDFNode rdf) { Node n = rdf.asNode(); if (n.isURI()) return uri(rdf.asResource()); if (n.isLiteral()) return literal( n.getLiteralLexicalForm(), n.getLiteralLanguage(), n.getLiteralDatatypeURI() ); throw new RuntimeException( "Cannot convert " + rdf + " to RDFQ.Any" ); }
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]" ; }
private Node getObject(Node subj, Node pred) { for( final Iterator<Triple> i = triples.iterator(); i.hasNext(); ) { Triple t = i.next(); if( subj.equals( t.getSubject() ) && pred.equals( t.getPredicate() ) ) { i.remove(); return t.getObject(); } } return null; }
public static Atom triple2Atom(Triple triple) { Node subject = triple.getSubject(); Node object = triple.getObject(); Node predicate = triple.getPredicate(); if (predicate.getURI().equals(URIUtils.RDF_TYPE.toString())) { return DefaultAtomFactory.instance().create(node2Predicate(object, 1), node2Term(subject)); } else { return DefaultAtomFactory.instance().create(node2Predicate(predicate, 2), node2Term(subject), node2Term(object)); } }
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) ; }
@Override public boolean accept(Triple t) { if (t.getSubject().isLiteral()) return true; if (t.getPredicate().isBlank() || t.getPredicate().isLiteral()) return true; return false; } } ) );
private static boolean isMagicProperty(PropertyFunctionRegistry registry, Triple pfTriple) { if ( ! pfTriple.getPredicate().isURI() ) return false ; if ( registry.manages(pfTriple.getPredicate().getURI()) ) return true ; return false ; }
public final String create(Node node) { if ( node.isURI() ) return labelForURI(node) ; if ( node.isLiteral() ) return labelForLiteral(node) ; if ( node.isBlank() ) return labelForBlank(node) ; if ( node.isVariable() ) return labelForVar(node) ; // Other?? return Long.toString(counter++) ; }
@Override protected void check(Triple t) { if ( Var.isVar(getGraph()) ) throw new QueryParseException("Variables not permitted in data quad", -1, -1) ; if ( Var.isVar(t.getSubject()) || Var.isVar(t.getPredicate()) || Var.isVar(t.getObject())) throw new QueryParseException("Variables not permitted in data quad", -1, -1) ; if ( t.getSubject().isLiteral() ) throw new QueryParseException("Literals not allowed as subjects in data", -1, -1) ; }
/** * Validate a triple add to see if it should reinvoke the hook. If so * then the inference will be restarted at next prepare time. Incremental * re-processing is not yet supported but in this case would be useful. */ @Override public boolean needsRerun(FBRuleInfGraph infGraph, Triple t) { return (t.getPredicate().getURI().startsWith(memberPrefix)); }
private String getModelName( Statement s ) { Node o = s.getObject().asNode(); return o.isLiteral() ? o.getLiteralLexicalForm(): o.getURI(); }
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) ; }
private static MetaGraph parse(Node graph) { if (graph.isURI()) { String uri = graph.getURI(); return parse(uri); } // return null and do not thrown an exception because this method may be // invoked during the deserialization of a QuadruplePattern. In such a // case the graph may not be an URI and the null value is useful on high // level to detect that no meta information has been parsed return null; }
@Override public Double doubleValue(Node node) { if(node.isLiteral()){ Object value = node.getLiteral().getValue(); if(value instanceof Double){ return (Double)value; } else { return super.doubleValue(node); } } else { throw new IllegalArgumentException("parsed node is not an Literal"); } }