Java Code Examples for com.hp.hpl.jena.graph.Node#getLiteralLexicalForm()
The following examples show how to use
com.hp.hpl.jena.graph.Node#getLiteralLexicalForm() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrettyPrinter.java From GeoTriples with Apache License 2.0 | 6 votes |
/** * Pretty-prints an RDF node and shortens URIs into QNames according to a * {@link PrefixMapping}. * @param n An RDF node * @return An N-Triples style textual representation with URIs shortened to QNames */ public static String toString(Node n, PrefixMapping prefixes) { if (n.isURI()) { return qNameOrURI(n.getURI(), prefixes); } if (n.isBlank()) { return "_:" + n.getBlankNodeLabel(); } if (n.isVariable()) { return "?" + n.getName(); } if (Node.ANY.equals(n)) { return "?ANY"; } // Literal String s = "\"" + n.getLiteralLexicalForm() + "\""; if (!"".equals(n.getLiteralLanguage())) { s += "@" + n.getLiteralLanguage(); } if (n.getLiteralDatatype() != null) { s += "^^" + qNameOrURI(n.getLiteralDatatypeURI(), prefixes); } return s; }
Example 2
Source File: RDFReader.java From marklogic-contentpump with Apache License 2.0 | 5 votes |
protected String object(Node node) { if (node.isLiteral()) { String text = node.getLiteralLexicalForm(); String type = node.getLiteralDatatypeURI(); String lang = node.getLiteralLanguage(); if (lang == null || "".equals(lang)) { lang = ""; } else { lang = " xml:lang='" + escapeXml(lang) + "'"; } if ("".equals(lang)) { if (type == null) { type = "http://www.w3.org/2001/XMLSchema#string"; } type = " datatype='" + escapeXml(type) + "'"; } else { type = ""; } return "<sem:object" + type + lang + ">" + escapeXml(text) + "</sem:object>"; } else if (node.isBlank()) { return "<sem:object>http://marklogic.com/semantics/blank/" + Long.toHexString( hash64(fuse(scramble(milliSecs),randomValue), node.getBlankNodeLabel())) +"</sem:object>"; } else { return "<sem:object>" + escapeXml(node.toString()) + "</sem:object>"; } }
Example 3
Source File: CloudGraph.java From SolRDF with Apache License 2.0 | 5 votes |
/** * Builds a DELETE query. * * @param triple the triple (maybe a pattern?) that must be deleted. * @return a DELETE query. */ String deleteQuery(final Triple triple) { final StringBuilder builder = new StringBuilder(); if (triple.getSubject().isConcrete()) { and(builder).append(fq(Field.S, asNt(triple.getSubject()))); } if (triple.getPredicate().isConcrete()) { and(builder).append(fq(Field.P, asNtURI(triple.getPredicate()))); } if (triple.getObject().isConcrete()) { and(builder); final Node o = triple.getObject(); if (o.isLiteral()) { final String language = o.getLiteralLanguage(); if (Strings.isNotNullOrEmptyString(language)) { builder .append(fq(Field.LANG, language)) .append(" AND "); } final String literalValue = o.getLiteralLexicalForm(); final RDFDatatype dataType = o.getLiteralDatatype(); registry.get(dataType != null ? dataType.getURI() : null).addConstraint(builder, literalValue); } else { registry.catchAllInjector().addConstraint(builder, asNt(o)); } } return and(builder).append(fq(Field.C, graphNodeStringified)).toString(); }
Example 4
Source File: TypedNodeMaker.java From GeoTriples with Apache License 2.0 | 4 votes |
public String extractValue(Node node) { return node.getLiteralLexicalForm(); }
Example 5
Source File: LocalGraph.java From SolRDF with Apache License 2.0 | 4 votes |
/** * Builds a DELETE query. * * @param triple the triple (maybe a pattern?) that must be deleted. * @return a DELETE query. */ String deleteQuery(final Triple triple) { final StringBuilder builder = new StringBuilder(); if (triple.getSubject().isConcrete()) { builder .append(Field.S) .append(":\"") .append(asNt(triple.getSubject())) .append("\""); } if (triple.getPredicate().isConcrete()) { if (builder.length() != 0) { builder.append(" AND "); } builder .append(Field.P) .append(":\"") .append(asNtURI(triple.getPredicate())) .append("\""); } if (triple.getObject().isConcrete()) { if (builder.length() != 0) { builder.append(" AND "); } final Node o = triple.getObject(); if (o.isLiteral()) { final String language = o.getLiteralLanguage(); builder .append(Field.LANG) .append(":") .append(isNotNullOrEmptyString(language) ? language : NULL_LANGUAGE) .append(" AND "); final String literalValue = o.getLiteralLexicalForm(); final RDFDatatype dataType = o.getLiteralDatatype(); registry.get(dataType != null ? dataType.getURI() : null).addConstraint(builder, literalValue); } else { registry.catchAllInjector().addConstraint(builder, asNt(o)); } } return builder .append(" AND ") .append(Field.C) .append(":\"") .append(graphNodeStringified) .append("\"") .toString(); }
Example 6
Source File: LocalGraph.java From SolRDF with Apache License 2.0 | 4 votes |
SolrIndexSearcher.QueryCommand queryCommand(final Triple pattern, final SortSpec sortSpec) throws SyntaxError { final SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand(); cmd.setQuery(new MatchAllDocsQuery()); cmd.setSort(sortSpec.getSort()); cmd.setLen(queryFetchSize); cmd.setFlags(cmd.getFlags() | SolrIndexSearcher.GET_DOCSET); final List<Query> filters = new ArrayList<Query>(); final Node s = pattern.getMatchSubject(); final Node p = pattern.getMatchPredicate(); final Node o = pattern.getMatchObject(); if (s != null) { filters.add(new TermQuery(new Term(Field.S, asNt(s)))); } if (p != null) { filters.add(new TermQuery(new Term(Field.P, asNtURI(p)))); } if (o != null) { if (o.isLiteral()) { final String language = o.getLiteralLanguage(); filters.add( isNotNullOrEmptyString(language) ? languageTermQuery(language) : NULL_LANGUAGE_TERM_QUERY); final String literalValue = o.getLiteralLexicalForm(); final RDFDatatype dataType = o.getLiteralDatatype(); registry.get( dataType != null ? dataType.getURI() : null).addFilterConstraint(filters, literalValue, request); } else { filters.add(new TermQuery(new Term(Field.TEXT_OBJECT, asNt(o)))); } } filters.add(graphTermQuery); cmd.setFilterList(filters); return cmd; }