private Object transform(Literal literal) { IRI type = literal.getDatatype(); Function<Literal, Object> getter = literalGetters.get(type); if (getter == null) throw new RuntimeException("no getter for Literal defined that can handle literal with datatype [" + type + "]"); return getter.apply(literal); }
private Object transform(Literal literal) { IRI type = literal.getDatatype(); Function<Literal, Object> getter = literalGetters.get(type); if (getter == null) throw new RuntimeException("no getter for Literal defined that can handle literal with datatype [" + type + "]"); return getter.apply(literal); }
@Override boolean checkTuple(Tuple t) { if(! (t.line.get(1) instanceof Literal)) return false; Literal literal = (Literal) t.line.get(1); return literal.getDatatype() == datatype || literal.getDatatype().equals(datatype); }
@Override boolean checkTuple(Tuple t) { if(! (t.line.get(1) instanceof Literal)) return false; Literal literal = (Literal) t.line.get(1); return literal.getDatatype() == datatype || literal.getDatatype().equals(datatype); }
public static Optional<Boolean> getBooleanValue(Model theGraph, Resource theSubj, IRI thePred) { Optional<Literal> aLitOpt = getLiteral(theGraph, theSubj, thePred); if (!aLitOpt.isPresent()) { return Optional.empty(); } else { Literal aLiteral = (Literal)aLitOpt.get(); return (aLiteral.getDatatype() == null || !aLiteral.getDatatype().equals(XMLSchema.BOOLEAN)) && !aLiteral.getLabel().equalsIgnoreCase("true") && !aLiteral.getLabel().equalsIgnoreCase("false") ? Optional.empty() : Optional.of(Boolean.valueOf(aLiteral.getLabel())); } }
/** * Checks whether the supplied literal is a "simple literal". A "simple literal" is a literal with no * language tag and the datatype {@link XMLSchema#STRING}. * * @see <a href="http://www.w3.org/TR/sparql11-query/#simple_literal">SPARQL Simple Literal * Documentation</a> */ public static boolean isSimpleLiteral(Literal l) { return !Literals.isLanguageLiteral(l) && l.getDatatype().equals(XMLSchema.STRING); }
/** * Checks whether the supplied literal is a "string literal". A "string literal" is either a simple * literal, a plain literal with language tag, or a literal with datatype xsd:string. * * @see <a href="http://www.w3.org/TR/sparql11-query/#func-string">SPARQL Functions on Strings * Documentation</a> */ public static boolean isStringLiteral(Literal l) { IRI datatype = l.getDatatype(); return Literals.isLanguageLiteral(l) || datatype.equals(XMLSchema.STRING); }
/** * Checks whether the supplied literal is a "string literal". A "string literal" is either a simple * literal, a plain literal with language tag, or a literal with datatype xsd:string. * * @see <a href="http://www.w3.org/TR/sparql11-query/#func-string">SPARQL Functions on Strings * Documentation</a> */ public static boolean isStringLiteral(Literal l) { IRI datatype = l.getDatatype(); return Literals.isLanguageLiteral(l) || datatype.equals(XMLSchema.STRING); }
/** * Checks whether the supplied literal is a "simple literal". A "simple literal" is a literal with no * language tag and the datatype {@link XMLSchema#STRING}. * * @see <a href="http://www.w3.org/TR/sparql11-query/#simple_literal">SPARQL Simple Literal * Documentation</a> */ public static boolean isSimpleLiteral(Literal l) { return !Literals.isLanguageLiteral(l) && l.getDatatype().equals(XMLSchema.STRING); }
private long convertPeriodToMillis(Literal literal, IRI unit) { String stringVal = literal.getLabel(); IRI dataType = literal.getDatatype(); checkArgument(dataType.equals(XMLSchema.INTEGER) || dataType.equals(XMLSchema.INT), String .format("Invalid data type for period duration. Data Type must be of type %s or %s .", XMLSchema.INTEGER, XMLSchema.INT)); checkArgument(XMLDatatypeUtil.isValidInteger(stringVal) || XMLDatatypeUtil.isValidInt(stringVal), "Invalid duration value."); return convertToMillis(Integer.parseInt(stringVal), unit); }
private byte[] literal2data(Literal literal, boolean create) throws IOException { return literal2data(literal.getLabel(), literal.getLanguage(), literal.getDatatype(), create); }
private void checkForSearchType(Value val) { if (HALYARD.SEARCH_TYPE.equals(val) ||((val instanceof Literal) && HALYARD.SEARCH_TYPE.equals(((Literal)val).getDatatype()))) { throw new IncompatibleOperationException(); } } @Override
private Instant convertToInstant(Literal literal) { String stringVal = literal.getLabel(); IRI dataType = literal.getDatatype(); checkArgument(dataType.equals(XMLSchema.DATETIME) || dataType.equals(XMLSchema.DATE), String.format("Invalid data type for date time. Data Type must be of type %s or %s .", XMLSchema.DATETIME, XMLSchema.DATE)); checkArgument(XMLDatatypeUtil.isValidDateTime(stringVal) || XMLDatatypeUtil.isValidDate(stringVal), "Invalid date time value."); return literal.calendarValue().toGregorianCalendar().toInstant(); }
private byte[] literal2data(Literal literal, boolean create) throws IOException { return literal2data(literal.getLabel(), literal.getLanguage(), literal.getDatatype(), create); }
/** * Creates a copy tool parent time offset {@link RyaStatement} from the specified offset. * @param timeOffset the copy tool parent time offset. (in milliseconds). * @return the {@link RyaStatement} for the copy tool parent time offset. */ public static RyaStatement createTimeOffsetRyaStatement(final long timeOffset) { final Literal literal = VALUE_FACTORY.createLiteral(timeOffset); final RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); return new RyaStatement(RTS_SUBJECT_RYA, RTS_TIME_OFFSET_PREDICATE_RYA, timeObject); }
private StatementScanner createScanner(long startTime, Resource subj, IRI pred, Value obj, Resource...contexts) throws SailException { if ((obj instanceof Literal) && (HALYARD.SEARCH_TYPE.equals(((Literal)obj).getDatatype()))) { return new LiteralSearchStatementScanner(startTime, subj, pred, obj.stringValue(), contexts); } else { return new StatementScanner(startTime, subj, pred, obj, contexts); } }
@Override public void handleStatement(Statement st) throws RDFHandlerException { Value object = st.getObject(); StreamedStatement statement = new StreamedStatement(st.getSubject().stringValue(), st.getPredicate().stringValue(), object.stringValue(), (object instanceof Literal), ((object instanceof Literal)? ((Literal) object).getDatatype().stringValue(): null), (object instanceof Literal ? ((Literal) object).getLanguage().orElse(null) : null)); statements.add(statement); }
private byte[] literal2legacy(Literal literal) throws IOException { IRI dt = literal.getDatatype(); if (XMLSchema.STRING.equals(dt) || RDF.LANGSTRING.equals(dt)) return literal2data(literal.getLabel(), literal.getLanguage(), null, false); return literal2data(literal.getLabel(), literal.getLanguage(), dt, false); }
private byte[] literal2legacy(Literal literal) throws IOException { IRI dt = literal.getDatatype(); if (XMLSchema.STRING.equals(dt) || RDF.LANGSTRING.equals(dt)) return literal2data(literal.getLabel(), literal.getLanguage(), null, false); return literal2data(literal.getLabel(), literal.getLanguage(), dt, false); }
@Test public void testConvertLiteral_normalString() { final String expectedData = "Hello"; final RyaType ryaType = new RyaType(XMLSchema.STRING, expectedData); final Literal literal = RyaToRdfConversions.convertLiteral(ryaType); assertEquals(XMLSchema.STRING, literal.getDatatype()); assertEquals(expectedData, literal.getLabel()); assertFalse(literal.getLanguage().isPresent()); final Literal expectedLiteral = VF.createLiteral(expectedData); assertEquals(expectedLiteral, literal); } }