/** * Builds a String result for Elastic Search from an RDFNode * * @param node An RDFNode representing the value of a property for a given resource * @return If the RDFNode has a Literal value, among Boolean, Byte, Double, Float, Integer Long, * Short, this value is returned, converted to String * <p>If the RDFNode has a String Literal value, this value will be returned, surrounded by * double quotes * <p>If the RDFNode has a Resource value (URI) and toDescribeURIs is set to true, the value * of @getLabelForUri for the resource is returned, surrounded by double quotes. Otherwise, * the URI will be returned */ private String getStringForResult(RDFNode node, boolean getNodeLabel) { String result = ""; boolean quote = false; if (node.isLiteral()) { Object literalValue = node.asLiteral().getValue(); try { Class<?> literalJavaClass = node.asLiteral().getDatatype().getJavaClass(); if (literalJavaClass.equals(Boolean.class) || Number.class.isAssignableFrom(literalJavaClass)) { result += literalValue; } else { result = EEASettings.parseForJson(node.asLiteral().getLexicalForm()); quote = true; } } catch (java.lang.NullPointerException npe) { result = EEASettings.parseForJson(node.asLiteral().getLexicalForm()); quote = true; } } else if (node.isResource()) { result = node.asResource().getURI(); if (getNodeLabel) { result = getLabelForUri(result); } quote = true; } if (quote) { result = "\"" + result + "\""; } return result; }
protected static void addRangeTypes(Model result, Model schema) { Model toAdd = ModelFactory.createDefaultModel(); for (StmtIterator it = schema.listStatements(ANY, RDFS.range, ANY); it.hasNext(); ) { Statement s = it.nextStatement(); RDFNode type = s.getObject(); Property property = s.getSubject().as(Property.class); for (StmtIterator x = result.listStatements(ANY, property, ANY); x.hasNext(); ) { RDFNode ob = x.nextStatement().getObject(); if (ob.isResource()) toAdd.add((Resource) ob, RDF.type, type); } } result.add(toAdd); }
/** Answer the resource at the end of the path, if defined, or null */ public Resource getTerminalResource() { RDFNode n = getTerminal(); return (n != null && n.isResource()) ? (Resource) n : null; }