本文整理汇总了Java中org.apache.jena.datatypes.xsd.XSDDateTime类的典型用法代码示例。如果您正苦于以下问题:Java XSDDateTime类的具体用法?Java XSDDateTime怎么用?Java XSDDateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XSDDateTime类属于org.apache.jena.datatypes.xsd包,在下文中一共展示了XSDDateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLiteralTypeFromValue
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
/**
* Get literal type based on class of the value instance.
*
* @param value the requested value
* @return the value's literal type, null if not recognized
*/
private int getLiteralTypeFromValue(Object value) {
if (value instanceof Integer) {
return LiteralType.INTEGER;
} else if (value instanceof Double) {
return LiteralType.DOUBLE;
} else if (value instanceof Float) {
return LiteralType.FLOAT;
} else if (value instanceof String) {
return LiteralType.STRING;
} else if (value instanceof Long) {
return LiteralType.LONG;
} else if (value instanceof Boolean) {
return LiteralType.BOOLEAN;
} else if (value instanceof XSDDateTime) {
return LiteralType.DATETIME;
}
return 0;
}
示例2: getJDateTime
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
protected DateTime getJDateTime() {
XSDDateTime xdt = getXSDDateTime();
if (getDatatype().equals(XSD.dateTime.getURI())) {
int ms = (int)Math.round( 1000.0 * (xdt.getSeconds() - xdt.getFullSeconds()) );
DateTime jdt =
new DateTime(xdt.getYears(), xdt.getMonths(), xdt.getDays(), xdt.getHours(), xdt.getMinutes(), xdt.getFullSeconds(), ms, DateTimeZone.UTC);
return jdt;
} else if (getDatatype().equals(XSD.date.getURI())) {
return new DateTime(xdt.getYears(), xdt.getMonths(), xdt.getDays(), 0, 0);
} else if (getDatatype().equals(XSD.gYearMonth.getURI())) {
return new DateTime(xdt.getYears(), xdt.getMonths(), 0, 0, 0);
} else if (getDatatype().equals(XSD.gYear.getURI())) {
return new DateTime(xdt.getYears(), 1, 0, 0, 0);
} else {
throw new EpiException("Unsupport date time format: " + getDatatype());
}
}
示例3: testSimpleDiff
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
@Test
public void testSimpleDiff() throws Exception {
Model model2 = hydrateAndModifySecondModel();
String sparql = DiffToSparqlInsertUpdateBuilder.buildSparqlInsertUpdate(
RDFDifferenceBuilder.buildDifference(model, model2));
System.out.println(sparql);
assertTrue(sparql.startsWith("DELETE"));
Resource res2 = model2.createResource("http://example/com/Playpen2#foobarFoo");
StmtIterator it = model2.listStatements(res2, prop1, (RDFNode) null);
Statement stmt = it.nextStatement();
assertTrue(stmt.getObject().asLiteral().getBoolean() == false);
it = model2.listStatements(res2, prop2, (RDFNode) null);
stmt = it.nextStatement();
assertTrue(stmt.getObject().asLiteral().getLong() == 1);
it = model2.listStatements(res2, prop3, (RDFNode) null);
stmt = it.nextStatement();
XSDDateTime date = (XSDDateTime) stmt.getObject().asLiteral().getValue();
it = model2.listStatements(res2, prop4, (RDFNode) null);
stmt = it.nextStatement();
Literal lit = stmt.getObject().asLiteral();
String val = lit.getLexicalForm();
String dataType = lit.getDatatype().getURI();
assertTrue(val.equals("2017-01-01"));
assertTrue(dataType.equals(XSDDatatype.XSDdate.getURI()));
it = model2.listStatements(res2, prop5, (RDFNode) null);
stmt = it.nextStatement();
assertTrue(stmt.getObject().asLiteral().getString().equals("http://www.google.com"));
assertTrue(stmt.getObject().asLiteral().getDatatype().getURI().equals(XSDDatatype.XSDanyURI.getURI()));
}
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:37,代码来源:DiffToSparqlInsertUpdateBuilderTests.java
示例4: convertToSupportedValue
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
private Object convertToSupportedValue(Object value) {
if (value instanceof XSDDateTime) {
// spark only accepts java.sql.Timestamp and assumes it uses the current JVM timezone
// therefore this is not correct
// return new Timestamp(((XSDDateTime)value).asCalendar().getTimeInMillis());
// store the datetime as string instead
return value.toString();
}
return value;
}
示例5: getCrawlTime
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
public Calendar getCrawlTime(ProcessorController processorController) {
Model model = getModel();
ResIterator ri = getModel().listResourcesWithProperty(model.createProperty(R2R_PROCESSED));
while (ri.hasNext()) {
Resource crawl = ri.next();
if (processorController.getURI().equals(crawl.getProperty(model.createProperty(R2R_PROCESSED_BY)).getResource().getURI())) {
return ((XSDDateTime)crawl.getProperty(model.createProperty(R2R_PROCESSED_ON)).getLiteral().getValue()).asCalendar();
}
}
return null;
}
示例6: skip
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
public boolean skip(String researcherURI, String timestampField, int daysConsideredOld) throws Exception {
final AtomicLong dt = new AtomicLong();
sparqlQuery.select(String.format("SELECT ?ts WHERE {<%1$s> <" + timestampField + "> ?ts}", researcherURI), new ResultSetConsumer() {
public void useResultSet(ResultSet rs) {
if (rs.hasNext()) {
QuerySolution qs = rs.next();
dt.set(((XSDDateTime)qs.getLiteral("?ts").getValue()).asCalendar().getTimeInMillis());
}
}
});
long threshold = new DateTime().minusDays(daysConsideredOld).getMillis();
return dt.get() > threshold;
}
示例7: getXSDDateTime
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
protected XSDDateTime getXSDDateTime() {
Object val = value.getLiteralValue();
if (val instanceof XSDDateTime) {
return (XSDDateTime)val;
} else {
throw new EpiException("Not a date/time node");
}
}
示例8: RefTimeRepresentation
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
public RefTimeRepresentation(XSDDateTime time, RDFDatatype type) {
this.time = time;
int i_woy_year = 0;
int i_woy_week = 0;
if (type.equals(XSDDatatype.XSDdateTime)) {
bcal = new BritishCalendar(
time.getYears(), time.getMonths()-1, time.getDays(),
time.getHours(), time.getMinutes(), time.getFullSeconds() );
// Remove any trailing fractional seconds if present
ref = NodeFactory.createURI("http://reference.data.gov.uk/id/gregorian-instant/" + value.getLiteralLexicalForm().replaceAll("\\.[0-9]*$", ""));
i_woy_year = CalendarUtils.getWeekOfYearYear(bcal);
i_woy_week = bcal.get(Calendar.WEEK_OF_YEAR);
new CalendarInstant(model, bcal, true);
new CalendarDay(model, bcal, true);
new CalendarWeek(model, i_woy_year, i_woy_week, false, false);
} else if (type.equals(XSDDatatype.XSDdate)) {
bcal = new BritishCalendar(
time.getYears(), time.getMonths()-1, time.getDays());
ref = NodeFactory.createURI("http://reference.data.gov.uk/id/day/" + value.getLiteralLexicalForm());
i_woy_year = CalendarUtils.getWeekOfYearYear(bcal);
i_woy_week = bcal.get(Calendar.WEEK_OF_YEAR);
new CalendarDay(model, bcal, true);
new CalendarWeek(model, i_woy_year, i_woy_week, false, false);
} else {
ref = NodeFactory.createURI("http://reference.data.gov.uk/id/year/" + time.getYears());
}
week = NodeFactory.createURI("http://reference.data.gov.uk/id/week/"
+ String.format("%04d", i_woy_year)
+ "-W" + String.format("%02d", i_woy_week));
new CalendarYear(model, time.getYears(), false, false);
}
示例9: parseExpectedXsdDateTimeValue
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
/**
* Parses an RDFNode that is expected to be a literal of type xsd:dateTime into a Java Calendar
* object.
* @param node a node representing an xsd:dateTime literal
* @return a Calendar representation of the expressed dateTime
*/
private static Calendar parseExpectedXsdDateTimeValue(final RDFNode node) {
final Object value = node.asLiteral().getValue();
if (value instanceof XSDDateTime) {
return ((XSDDateTime) value).asCalendar();
} else {
throw new IllegalArgumentException("Expected an xsd:dateTime!");
}
}
示例10: testLength
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
private String testLength(XSDDateTime datetimeStart, XSDDateTime datetimeEnd) {
long diff = datetimeEnd.asCalendar().getTimeInMillis() - datetimeStart.asCalendar().getTimeInMillis();
return String.format("%02d:%02d:%02d",
TimeUnit.MILLISECONDS.toHours(diff),
TimeUnit.MILLISECONDS.toMinutes(diff) -
TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(diff)),
TimeUnit.MILLISECONDS.toSeconds(diff) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(diff)));
}
示例11: BaseTestCaseResultImpl
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
protected BaseTestCaseResultImpl(Resource element, String testCaseUri, RLOGLevel severity, String message, XSDDateTime timestamp) {
this.element = element;
this.testCaseUri = testCaseUri;
this.severity = severity;
this.message = message;
this.timestamp = timestamp;
}
示例12: convertDateLiteral
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if (dt.equals(XSDDatatype.XSDgMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.get(Calendar.DAY_OF_MONTH) + " de "
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL) + " de "
+ calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
// fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
}
}
}
return s;
}
示例13: convertDateLiteral
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
private String convertDateLiteral(LiteralLabel lit){
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if(dt.equals(XSDDatatype.XSDgMonth)){
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL);
} else if(dt.equals(XSDDatatype.XSDgMonthDay)){
s = calendar.get(Calendar.DAY_OF_MONTH) + calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL);
} else if(dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " " + calendar.get(Calendar.YEAR);
} else if(dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " " + calendar.get(Calendar.DAY_OF_MONTH)
+ ", " + calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
//fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
}
}
}
return s;
}
示例14: convertDateLiteral
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if (dt.equals(XSDDatatype.XSDgMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.get(Calendar.DAY_OF_MONTH) + " "
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
// fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
}
}
}
return s;
}
示例15: convertDateLiteral
import org.apache.jena.datatypes.xsd.XSDDateTime; //导入依赖的package包/类
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if (dt.equals(XSDDatatype.XSDgMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " "
+ calendar.get(Calendar.DAY_OF_MONTH) + ", " + calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
// fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
}
}
}
return s;
}