Refine search
@Override public String toString() { return FmtUtils.stringForRDFNode(term); } }
@Override protected void details(IndentedWriter out, SerializationContext sCxt) { out.print(Lib.className(this)) ; out.println() ; out.incIndent() ; FmtUtils.formatPattern(out, pattern, sCxt) ; out.decIndent() ; } }
public static String stringForTriple(Triple triple, PrefixMapping prefixMap) { return stringForTriple(triple, sCxt(prefixMap)) ; }
public static String stringForQuad(Quad quad, PrefixMapping prefixMap) { return stringForQuad(quad, sCxt(prefixMap)) ; }
public static String stringForObject(Object obj) { if ( obj == null ) return "<<null>>" ; if ( obj instanceof RDFNode ) return stringForRDFNode((RDFNode)obj) ; if ( obj instanceof Node ) return stringForNode((Node)obj) ; return obj.toString() ; }
public static void stringForNode(StringBuilder result, Node n, SerializationContext context) { if ( n == null ) { result.append("<<null>>") ; return ; } // mappable? if ( context != null && context.getBNodeMap() != null ) { String str = context.getBNodeMap().asString(n) ; if ( str != null ) { result.append(str) ; return ; } } if ( n.isBlank() ) { result.append("_:").append(n.getBlankNodeLabel()) ; } else if ( n.isLiteral() ) { stringForLiteral(result, (Node_Literal)n, context) ; } else if ( n.isURI() ) { String uri = n.getURI() ; stringForURI(result, uri, context) ; } else if ( n.isVariable() ) { result.append("?").append(n.getName()) ; } else if ( n.equals(Node.ANY) ) { result.append("ANY") ; } else { Log.warn(FmtUtils.class, "Failed to turn a node into a string: " + n) ; result.append(n.toString()) ; } }
private void docEntity(Node g, Node s, List<Quad> batch) { // One document per entity String x = TextQueryFuncs.subjectToString(s) ; String gx = TextQueryFuncs.graphNodeToString(g) ; Entity entity = new Entity(x, gx) ; String graphField = defn.getGraphField() ; if ( defn.getGraphField() != null ) entity.put(graphField, gx) ; for ( Quad quad : batch ) { Node p = quad.getPredicate() ; String field = defn.getField(p) ; if ( field == null ) continue ; Node o = quad.getObject() ; String val = null ; if ( o.isURI() ) val = o.getURI() ; else if ( o.isLiteral() ) val = o.getLiteralLexicalForm() ; else { log.warn("Not a literal value for mapped field-predicate: " + field + " :: " + FmtUtils.stringForString(field)) ; continue ; } entity.put(field, val) ; } indexer.addEntity(entity) ; }
public void addDescribeNode(Node node) { if ( node.isVariable() ) { addResultVar(node) ; return ; } if ( node.isURI() || node.isBlank() ) { if ( !resultNodes.contains(node) ) resultNodes.add(node); return ; } if ( node.isLiteral() ) throw new QueryException("Result node is a literal: "+FmtUtils.stringForNode(node)) ; throw new QueryException("Result node not recognized: "+node) ; }
/** Create an Entity from a quad (as g/s/p/o). * Returns null if the quad is not a candidate for indexing. */ public static Entity entityFromQuad(EntityDefinition defn , Node g , Node s , Node p , Node o ) { String field = defn.getField(p) ; if ( field == null ) return null ; if ( !o.isLiteral() ) { Log.warn(TextQuery.class, "Not a literal value for mapped field-predicate: " + field + " :: " + FmtUtils.stringForString(field)) ; return null ; } String x = TextQueryFuncs.subjectToString(s) ; String graphText = TextQueryFuncs.graphNodeToString(g) ; String language = o.getLiteral().language() ; RDFDatatype datatype = o.getLiteral().getDatatype() ; Entity entity = new Entity(x, graphText, language, datatype) ; entity.put(field, o.getLiteralLexicalForm()) ; return entity ; }
StringBuffer sb = new StringBuffer(); sb.append("SHACL Function "); sb.append(SSE.str(NodeFactory.createURI(uri), model)); sb.append("("); for(int i = 0; i < args.size(); i++) { IndentedWriter iOut = new IndentedWriter(bos); ExprUtils.fmtSPARQL(iOut, expr, new SerializationContext(model)); iOut.flush(); sb.append(bos.toString()); sb.append(FmtUtils.stringForNode(result.asNode(), model)); ExecStatistics stats = new ExecStatistics(sb.toString(), getQueryString(), endTime - startTime, startTime, NodeFactory.createURI(uri)); ExecStatisticsManager.get().addSilently(Collections.singleton(stats));
private void buildTreeString(StringBuilder sb, boolean stopIfChildIsResourceNode, int depth, SerializationContext context) { // render current node String ren; if(isLiteralNode() && !isLiteralValueNode()) { ren = "?^^" + FmtUtils.stringForNode(NodeFactory.createURI(this.getDatatype().getURI()), context); } else { ren = FmtUtils.stringForNode(this.getData(), context); } sb.append(ren);//.append("\n"); // render edges + children if (isRoot() || !isResourceNode() || (isResourceNode() && !stopIfChildIsResourceNode)) { for(Node edge : getEdges()) { for (RDFResourceTree child : getChildren(edge)) { sb.append("("); if (edge != null) { sb.append(FmtUtils.stringForNode(edge, context)); sb.append("("); } child.buildTreeString(sb, stopIfChildIsResourceNode, depth + 1, context); sb.append(")"); sb.append(")"); // sb.append("\n"); } } } }
protected void checkQuad(Node graph, Node subject, Node predicate, Node object, long line, long col) { // Allow blank nodes - syntax may restrict more. if ( graph != null && !graph.isURI() && !graph.isBlank() ) { errorHandler.error("Graph name is not a URI or blank node: " + FmtUtils.stringForNode(graph), line, col); throw new RiotException("Bad graph name: " + graph); } checkTriple(subject, predicate, object, line, col); }
@Override public List<String> getFunctionalSyntaxArguments() { List<String> results = new LinkedList<>(); results.add(FmtUtils.stringForNode(NodeFactory.createLiteral(queryString))); NodeExpression input = getInput(); if(input != null) { results.add(input.getFunctionalSyntax()); } return results; }
@Test public void stringForQuadEncoding() { Node n1 = NodeFactory.createURI("q1") ; Quad quad = new Quad(n1, getTriple()) ; assertEquals("<q1> <n1> <n2> \"l3\"", stringForQuad(quad)) ; }
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 ; }
@Override public NodeValue exec(NodeValue v) { Node n = v.asNode() ; if ( ! n.isURI() ) throw new ExprEvalException("Not a URI: "+FmtUtils.stringForNode(n)) ; String str = n.getNameSpace() ; return NodeValue.makeString(str) ; } }
@Override public String encode(Node node) { if ( node.isBlank() ) return "_:"+node.getBlankNodeId().getLabelString() ; String s = FmtUtils.stringForNode(node, prefixMapping) ; return s ; }
@Override public NodeValue exec(NodeValue v) { Node n = v.asNode() ; if ( ! n.isURI() ) throw new ExprEvalException("Not a URI: "+FmtUtils.stringForNode(n)) ; String str = n.getLocalName() ; return NodeValue.makeString(str) ; } }
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; }