Java Code Examples for org.openrdf.model.Value#stringValue()
The following examples show how to use
org.openrdf.model.Value#stringValue() .
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: SesameTransformationRepairPosLength.java From trainbenchmark with Eclipse Public License 1.0 | 6 votes |
@Override public void activate(final Collection<SesamePosLengthMatch> matches) throws RepositoryException { final RepositoryConnection con = driver.getConnection(); final ValueFactory vf = driver.getValueFactory(); final URI lengthProperty = vf.createURI(BASE_PREFIX + LENGTH); for (final SesamePosLengthMatch match : matches) { final Resource segment = match.getSegment(); final Value length = match.getLength(); final RepositoryResult<Statement> statementsToRemove = con.getStatements(segment, lengthProperty, length, true); while (statementsToRemove.hasNext()) { final Statement oldStatement = statementsToRemove.next(); con.remove(oldStatement); } final Integer lengthInteger = new Integer(length.stringValue()); final Integer newLengthInteger = -lengthInteger + 1; final Literal newLength = vf.createLiteral(newLengthInteger); final Statement newStatement = vf.createStatement(segment, lengthProperty, newLength); con.add(newStatement); } }
Example 2
Source File: AbstractRMLProcessor.java From GeoTriples with Apache License 2.0 | 6 votes |
@Override public void run() { List<Value> objects = processObjectMap(objectMap, node, map, subject, predicate, dataset); for (Value object : objects) { if (object.stringValue() != null) { Set<GraphMap> graphs = pom.getGraphMaps(); if (graphs.isEmpty()) dataset.add(subject, predicate, object); else for (GraphMap graph : graphs) { Resource graphResource = new URIImpl(graph .getConstantValue().toString()); dataset.add(subject, predicate, object, graphResource); } } } }
Example 3
Source File: ColorsEnumExtension.java From database with GNU General Public License v2.0 | 6 votes |
/** * Attempts to convert the supplied RDF value into a colors enum * representation. Tests for a literal value with the correct datatype * that can be converted to one of the colors in the {@link Color} enum * based on the string value of the literal's label. Each {@link Color} * in the enum maps to a particular byte. This byte is encoded in a * delegate {@link XSDByteIV}, and an {@link LiteralExtensionIV} is returned that * wraps the native type. */ public LiteralExtensionIV createIV(final Value value) { if (value instanceof Literal == false) throw new IllegalArgumentException(); final Literal l = (Literal) value; if (l.getDatatype() == null || !color.equals(l.getDatatype())) throw new IllegalArgumentException(); final String s = value.stringValue(); final Color c; try { c = Enum.valueOf(Color.class, s); } catch (IllegalArgumentException ex) { // not a valid color return null; } final AbstractLiteralIV delegate = new XSDNumericIV(c.getByte()); return new LiteralExtensionIV(delegate, color.getIV()); }
Example 4
Source File: SparqlEvaluator.java From anno4j with Apache License 2.0 | 6 votes |
private void writeLiteral(StringBuilder sb, Value value) { Literal lit = (Literal) value; sb.append("\""); String label = value.stringValue(); sb.append(encodeString(label)); sb.append("\""); if (lit.getDatatype() != null) { // Append the literal's datatype (possibly written as an // abbreviated URI) sb.append("^^"); writeURI(sb, lit.getDatatype()); } if (lit.getLanguage() != null) { // Append the literal's language sb.append("@"); sb.append(lit.getLanguage()); } }
Example 5
Source File: TupleQueryExecutor.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private boolean processRow( long row, BindingSet bindingSet, QualifiedIdentityResultCallback callback ) { final Value identifier = bindingSet.getValue( "reference" ); //TODO Shall we throw an exception if there is no binding for identifier = query parser is not right if( identifier == null ) { return true; } final String identity = identifier.stringValue(); final EntityReference entityReference = EntityReference.parseEntityReference( identity ); return callback.processRow( row, entityReference ); }
Example 6
Source File: EncodeDecodeValue.java From database with GNU General Public License v2.0 | 5 votes |
/** * Encode an RDF {@link Value} as it should appear if used in a SPARQL * query. E.g., a literal will look like <code>"abc"</code>, * <code>"abc"@en</code> or * <code>"3"^^xsd:int. A URI will look like <code><http://www.bigdata.com/></code> * . * * @param v * The value (optional). * * @return The encoded value -or- <code>null</code> if the argument is * <code>null</code>. * * @throws IllegalArgumentException * if the argument is a {@link BNode}. */ public static String encodeValue(final Value v) { if(v == null) return null; if (v instanceof BNode) throw new IllegalArgumentException(); if (v instanceof URI) { return "<" + v.stringValue() + ">"; } if (v instanceof Literal) { final Literal lit = (Literal) v; final StringBuilder sb = new StringBuilder(); sb.append("\""); sb.append(lit.getLabel()); sb.append("\""); if (lit.getLanguage() != null) { sb.append("@"); sb.append(lit.getLanguage()); } if (lit.getDatatype() != null) { sb.append("^^"); sb.append(encodeValue(lit.getDatatype())); } return sb.toString(); } throw new AssertionError(); }
Example 7
Source File: XSDStringExtension.java From database with GNU General Public License v2.0 | 5 votes |
public LiteralExtensionIV createIV(final Value value) { if (value instanceof Literal == false) throw new IllegalArgumentException(); if (value.stringValue().length() > maxInlineStringLength) { // Too large to inline. return null; } final Literal lit = (Literal) value; final URI dt = lit.getDatatype(); // Note: URI.stringValue() is efficient.... if (dt == null || !XSD.STRING.stringValue().equals(dt.stringValue())) throw new IllegalArgumentException(); final String s = value.stringValue(); final FullyInlineTypedLiteralIV<BigdataLiteral> delegate = new FullyInlineTypedLiteralIV<BigdataLiteral>(// s, // label null, // no language null // no datatype ); return new LiteralExtensionIV<BigdataLiteral>(delegate, xsdStringURI.getIV()); }
Example 8
Source File: SparqlGenerator.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
private String sparql(final Value val) { if (val instanceof Literal) { return val.toString(); } else if (val instanceof URI) { return '<' + val.stringValue() + '>'; } else { throw new IllegalArgumentException(); } }
Example 9
Source File: CumulusRDFValueFactory.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * Creates a CumulusRDF native value from a given {@link Value}. * * @param value the incoming {@link Value}. * @return a CumulusRDF native value. */ public static Value makeNativeValue(final Value value) { if (value == null || value instanceof INativeCumulusValue) { return value; } if (value instanceof URI) { return new NativeCumulusURI(value.stringValue()); } else if (value instanceof Literal) { final Literal lit = (Literal) value; final String label = lit.getLabel(), language = lit.getLanguage(); final URI datatype = lit.getDatatype(); if (language != null) { return new NativeCumulusLiteral(label, language); } else if (datatype != null) { return new NativeCumulusLiteral(label, datatype); } else { return new NativeCumulusLiteral(label); } } else if (value instanceof BNode) { return new NativeCumulusBNode(value.stringValue()); } return value; }
Example 10
Source File: ConstVar.java From neo4j-sparql-extension with GNU General Public License v3.0 | 5 votes |
public ConstVar(Value value) { if (value == null) { throw new IllegalArgumentException("value can not be null"); } String uniqueStringForValue = value.stringValue(); if (value instanceof Literal) { uniqueStringForValue += "-lit"; // we need to append datatype and/or language tag to ensure a unique var name (see SES-1927) Literal lit = (Literal) value; if (lit.getDatatype() != null) { uniqueStringForValue += "-" + lit.getDatatype().stringValue(); } if (lit.getLanguage() != null) { uniqueStringForValue += "-" + lit.getLanguage(); } } else if (value instanceof BNode) { uniqueStringForValue += "-node"; } else { uniqueStringForValue += "-uri"; } setName("-const-" + uniqueStringForValue); setConstant(true); setAnonymous(true); setValue(value); }
Example 11
Source File: SparqlEvaluator.java From anno4j with Apache License 2.0 | 4 votes |
private void writeURI(StringBuilder sb, Value value) { sb.append("<"); String uri = value.stringValue(); sb.append(encodeURIString(uri)); sb.append(">"); }
Example 12
Source File: ProxyGOMTest.java From database with GNU General Public License v2.0 | 4 votes |
private Object indentOut(IGPO clss, int indent) { Value lbl = clss.getValue(RDFS.LABEL); final String display = lbl == null ? clss.getId().stringValue() : lbl .stringValue(); return indents.substring(0, indent) + display; }
Example 13
Source File: EpochExtension.java From database with GNU General Public License v2.0 | 4 votes |
/** * Attempts to convert the supplied value into an epoch representation. * Tests for a literal value with the correct datatype that can be converted * to a positive long integer. Encodes the long in a delegate * {@link XSDLongIV}, and returns an {@link LiteralExtensionIV} to wrap the native * type. */ public LiteralExtensionIV createIV(final Value value) { if (value instanceof Literal == false) throw new IllegalArgumentException(); final Literal lit = (Literal) value; final URI dt = lit.getDatatype(); if (dt == null || !EPOCH.stringValue().equals(dt.stringValue())) throw new IllegalArgumentException(); final String s = value.stringValue(); final long l = XMLDatatypeUtil.parseLong(s); final AbstractLiteralIV delegate = new XSDNumericIV(l); return new LiteralExtensionIV(delegate, epoch.getIV()); }
Example 14
Source File: RDFClass.java From anno4j with Apache License 2.0 | 4 votes |
private BigInteger getBigInteger(URI pred) { Value value = model.filter(self, pred, null).objectValue(); if (value == null) return null; return new BigInteger(value.stringValue()); }
Example 15
Source File: RegexBOp.java From database with GNU General Public License v2.0 | 4 votes |
/** * Lifted directly from Sesame's EvaluationStrategyImpl. * * FIXME The Pattern should be cached if the pattern argument and flags are * constants. * * @see <a href="http://sourceforge.net/apps/trac/bigdata/ticket/516"> * REGEXBOp should cache the Pattern when it is a constant </a> */ private boolean accept(final Value arg, final Value parg, final Value farg) { if (debug) { log.debug("regex var: " + arg); log.debug("regex pattern: " + parg); log.debug("regex flags: " + farg); //Fixme not sure why we weren't able pick up via properties log.debug(QueryHints.REGEX_MATCH_NON_STRING + ": " + this.getProperty(QueryHints.REGEX_MATCH_NON_STRING, QueryHints.DEFAULT_REGEX_MATCH_NON_STRING)); log.debug("matchNonString: " + this.matchNonString); } //BLZG-1200 changed to isPlainLiteral if (QueryEvaluationUtil.isPlainLiteral(arg) // BLZG-1780: Query Hint to cast to string || matchNonString ) { final String text; if(QueryEvaluationUtil.isPlainLiteral(arg)) { text = ((Literal) arg).getLabel(); } else { //Query Hint Override with explicit conversion text = arg.stringValue(); } if(debug) { log.debug("regex text: " + text); } try { // first check for cached pattern Pattern pattern = (Pattern) getProperty(Annotations.PATTERN); if (pattern == null) { // resolve the pattern. NB: NOT cached. pattern = getPattern(parg, farg); } if (Thread.interrupted()) { /* * Eagerly notice if the operator is interrupted. * * Note: Regex can be a high latency operation for a large * RDF Literal. Therefore we want to check for an interrupt * before each regex test. The Pattern code itself will not * notice an interrupt.... */ throw new RuntimeException(new InterruptedException()); } final boolean result = pattern.matcher(new InterruptibleCharSequence(text)).find(); return result; } catch (IllegalArgumentException ex) { throw new SparqlTypeErrorException(); } } else { if(debug) { log.debug("Unknown type: " + arg); } throw new SparqlTypeErrorException(); } }
Example 16
Source File: DateTimeExtension.java From database with GNU General Public License v2.0 | 4 votes |
/** * Attempts to convert the supplied value into an epoch representation. * Tests for a literal value with the correct datatype that can be converted * to a positive long integer. Encodes the long in a delegate * {@link XSDLongIV}, and returns an {@link LiteralExtensionIV} to wrap the native * type. */ public LiteralExtensionIV createIV(final Value value) { if (value instanceof Literal == false) throw new IllegalArgumentException(); final Literal lit = (Literal) value; final URI dt = lit.getDatatype(); final String s = value.stringValue(); /* * Returns the current time as UTC milliseconds from the epoch */ final long l = getTimestamp(s, defaultTZ); return createIV(l, dt); }
Example 17
Source File: RangeQueryOptimizationTest.java From cumulusrdf with Apache License 2.0 | 4 votes |
@Test public void queryOrderAscTest() throws RepositoryException, MalformedQueryException, QueryEvaluationException { Iterator<String> iter = _orderByAscQueries.iterator(); while (iter.hasNext()) { String query = iter.next(); TupleQuery cq = CUMULUS_CONNECTION.prepareTupleQuery(QueryLanguage.SPARQL, query); TupleQueryResult cRes = cq.evaluate(); String last = null; String current = null; while (cRes.hasNext()) { BindingSet bs = cRes.next(); Iterator<Binding> bindings = bs.iterator(); while (bindings.hasNext()) { Binding b = bindings.next(); Value v = b.getValue(); if (v instanceof Literal) { current = v.stringValue(); try { double currDouble = Double.parseDouble(current); double lastDouble; if (last == null) { lastDouble = -Double.MAX_VALUE; } else { lastDouble = Double.parseDouble(last); } assertTrue(currDouble >= lastDouble); last = current; } catch (NumberFormatException ne) { if (last == null) { last = ""; } assertTrue(last.compareTo(current) <= 0); last = current; } } } } } }
Example 18
Source File: RangeQueryOptimizationTest.java From cumulusrdf with Apache License 2.0 | 4 votes |
@Test public void queryOrderDescTest() throws RepositoryException, MalformedQueryException, QueryEvaluationException { Iterator<String> iter = _orderByDescQueries.iterator(); while (iter.hasNext()) { String query = iter.next(); TupleQuery cq = CUMULUS_CONNECTION.prepareTupleQuery(QueryLanguage.SPARQL, query); TupleQueryResult cRes = cq.evaluate(); String last = null; String current = null; while (cRes.hasNext()) { BindingSet bs = cRes.next(); Iterator<Binding> bindings = bs.iterator(); while (bindings.hasNext()) { Binding b = bindings.next(); Value v = b.getValue(); if (v instanceof Literal) { current = v.stringValue(); try { double currDouble = Double.parseDouble(current); double lastDouble; if (last == null) { lastDouble = Double.MAX_VALUE; } else { lastDouble = Double.parseDouble(last); } assertTrue(currDouble <= lastDouble); last = current; } catch (NumberFormatException ne) { if (last == null) { last = "_"; } assertTrue(last.compareTo(current) >= 0); last = current; } } } } } }