Java Code Examples for org.eclipse.rdf4j.model.vocabulary.XMLSchema#DATETIME
The following examples show how to use
org.eclipse.rdf4j.model.vocabulary.XMLSchema#DATETIME .
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: SmartUriAdapter.java From rya with Apache License 2.0 | 6 votes |
private static IRI determineType(final String data) { if (Ints.tryParse(data) != null) { return XMLSchema.INTEGER; } else if (Doubles.tryParse(data) != null) { return XMLSchema.DOUBLE; } else if (Floats.tryParse(data) != null) { return XMLSchema.FLOAT; } else if (isShort(data)) { return XMLSchema.SHORT; } else if (Longs.tryParse(data) != null) { return XMLSchema.LONG; } if (Boolean.parseBoolean(data)) { return XMLSchema.BOOLEAN; } else if (isByte(data)) { return XMLSchema.BYTE; } else if (isDate(data)) { return XMLSchema.DATETIME; } else if (isUri(data)) { return XMLSchema.ANYURI; } return XMLSchema.STRING; }
Example 2
Source File: XMLDatatypeUtil.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Maps a datatype QName from the javax.xml.namespace package to an XML Schema 1.0 URI for the corresponding * datatype. This method recognizes the XML Schema qname mentioned in {@link DatatypeConstants}. * * Note that Java 8 / 11 do not have constants for XML Schema 1.1 datatypes like xsd:dateTimeStamp. * * @param qname One of the XML Schema qnames from {@link DatatypeConstants}. * @return A URI for the specified datatype. * @throws IllegalArgumentException If the supplied qname was not recognized by this method. * @see DatatypeConstants */ public static IRI qnameToURI(QName qname) { if (DatatypeConstants.DATETIME.equals(qname)) { return XMLSchema.DATETIME; } else if (DatatypeConstants.DATE.equals(qname)) { return XMLSchema.DATE; } else if (DatatypeConstants.TIME.equals(qname)) { return XMLSchema.TIME; } else if (DatatypeConstants.GYEARMONTH.equals(qname)) { return XMLSchema.GYEARMONTH; } else if (DatatypeConstants.GMONTHDAY.equals(qname)) { return XMLSchema.GMONTHDAY; } else if (DatatypeConstants.GYEAR.equals(qname)) { return XMLSchema.GYEAR; } else if (DatatypeConstants.GMONTH.equals(qname)) { return XMLSchema.GMONTH; } else if (DatatypeConstants.GDAY.equals(qname)) { return XMLSchema.GDAY; } else if (DatatypeConstants.DURATION.equals(qname)) { return XMLSchema.DURATION; } else if (DatatypeConstants.DURATION_DAYTIME.equals(qname)) { return XMLSchema.DAYTIMEDURATION; } else if (DatatypeConstants.DURATION_YEARMONTH.equals(qname)) { return XMLSchema.YEARMONTHDURATION; } else { throw new IllegalArgumentException("QName cannot be mapped to an XML Schema URI: " + qname.toString()); } }
Example 3
Source File: DateTimeRyaTypeResolverTest.java From rya with Apache License 2.0 | 5 votes |
@Test public void testGarbageIn() throws Exception { String currentTime = "Blablabla"; RyaType ryaType = new RyaType(XMLSchema.DATETIME, currentTime ); Throwable threw=null; try { new DateTimeRyaTypeResolver().serialize(ryaType); } catch (java.lang.IllegalArgumentException exception) { threw = exception; } assertNotNull("Expected to catch bad format message.",threw); assertEquals("Caught bad format message.","Invalid format: \"Blablabla\"", threw.getMessage()); }
Example 4
Source File: DateTimeRyaTypeResolverTest.java From rya with Apache License 2.0 | 5 votes |
/** * Serialize a datetime string, then deserialize as a ryaType. * @param dateTimeString * @param type if null , use default: XMLSchema.DATETIME * @return * @throws RyaTypeResolverException */ private RyaType serializeAndDeserialize(String dateTimeString, IRI type ) throws RyaTypeResolverException { if (type == null) type = XMLSchema.DATETIME; RyaType ryaType = new RyaType(type, dateTimeString ); byte[] serialize = new DateTimeRyaTypeResolver().serialize(ryaType); return new DateTimeRyaTypeResolver().deserialize(serialize); }
Example 5
Source File: DateTimeCast.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected IRI getXsdDatatype() { return XMLSchema.DATETIME; }
Example 6
Source File: AccumuloRyaDAOTest.java From rya with Apache License 2.0 | 4 votes |
@Test public void testQueryDates() throws Exception { RyaIRI cpu = new RyaIRI(litdupsNS + "cpu"); RyaIRI loadPerc = new RyaIRI(litdupsNS + "loadPerc"); RyaType uri0 = new RyaType(XMLSchema.DATETIME, "1960-01-01"); // How handles local time RyaType uri1 = new RyaType(XMLSchema.DATETIME, "1992-01-01T+10:00"); // See Magadan Time RyaType uri2 = new RyaType(XMLSchema.DATETIME, "2000-01-01TZ"); // How it handles UTC. RyaType uri3 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.111Z"); RyaType uri4 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.111Z"); // duplicate RyaType uri5 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01-00:00"); RyaType uri6 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01Z"); // duplicate RyaType uri7 = new RyaType(XMLSchema.DATETIME, "-2000-01-01T00:00:01Z"); RyaType uri8 = new RyaType(XMLSchema.DATETIME, "111-01-01T00:00:01Z"); RyaType uri9 = new RyaType(XMLSchema.DATETIME, "12345-01-01T00:00:01Z"); dao.add(new RyaStatement(cpu, loadPerc, uri0)); dao.add(new RyaStatement(cpu, loadPerc, uri1)); dao.add(new RyaStatement(cpu, loadPerc, uri2)); dao.add(new RyaStatement(cpu, loadPerc, uri3)); dao.add(new RyaStatement(cpu, loadPerc, uri4)); dao.add(new RyaStatement(cpu, loadPerc, uri5)); dao.add(new RyaStatement(cpu, loadPerc, uri6)); dao.add(new RyaStatement(cpu, loadPerc, uri7)); dao.add(new RyaStatement(cpu, loadPerc, uri8)); dao.add(new RyaStatement(cpu, loadPerc, uri9)); AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine(); Collection<RyaStatement> coll = new ArrayList<>(); coll.add(new RyaStatement(null, loadPerc, uri0)); coll.add(new RyaStatement(null, loadPerc, uri1)); coll.add(new RyaStatement(null, loadPerc, uri2)); CloseableIteration<RyaStatement, RyaDAOException> iter = queryEngine.batchQuery(coll, conf); int count = 0; while (iter.hasNext()) { count++; iter.next(); } iter.close(); assertEquals("Three time zones should be normalized when stored, then normalized same when queried.",3, count); //now use batchscanner AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(conf); queryConf.setMaxRangesForScanner(2); coll = new ArrayList<>(); coll.add(new RyaStatement(null, loadPerc, uri0)); coll.add(new RyaStatement(null, loadPerc, uri1)); coll.add(new RyaStatement(null, loadPerc, uri2)); coll.add(new RyaStatement(null, loadPerc, uri3)); coll.add(new RyaStatement(null, loadPerc, uri4)); coll.add(new RyaStatement(null, loadPerc, uri5)); coll.add(new RyaStatement(null, loadPerc, uri6)); coll.add(new RyaStatement(null, loadPerc, uri7)); coll.add(new RyaStatement(null, loadPerc, uri8)); coll.add(new RyaStatement(null, loadPerc, uri9)); iter = queryEngine.batchQuery(coll, queryConf); count = 0; while (iter.hasNext()) { count++; iter.next(); } iter.close(); assertEquals("Variety of time specs, including BC, pre-1970, duplicate pair ovewrite,future, 3 digit year.",8, count); }
Example 7
Source File: DateTimeRyaTypeResolver.java From rya with Apache License 2.0 | 4 votes |
public DateTimeRyaTypeResolver() { super((byte) DATETIME_LITERAL_MARKER, XMLSchema.DATETIME); }
Example 8
Source File: DuplicateDataDetector.java From rya with Apache License 2.0 | 4 votes |
@Override public IRI getXmlSchemaUri() { return XMLSchema.DATETIME; }
Example 9
Source File: RyaTypeUtils.java From rya with Apache License 2.0 | 3 votes |
/** * Creates a date/time {@link RyaType} object. * @param value the {@link DateTime} object. * @return the {@link RyaType} with the data type set to * {@link XMLSchema#DATETIME} and the data set to the specified * {@code value}. */ public static RyaType dateRyaType(final DateTime value) { final StringBuffer sb = new StringBuffer(); ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC).printTo(sb, value.getMillis()); final String formattedDate = sb.toString(); return new RyaType(XMLSchema.DATETIME, formattedDate); }