AGTemporalCalendars.java
package com.franz.ag.examples;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.openrdf.model.Literal;
import com.franz.ag.AllegroGraph;
import com.franz.ag.AllegroGraphConnection;
import com.franz.ag.AllegroGraphException;
import com.franz.ag.Cursor;
public class AGTemporalCalendars {
@param
@throws
public static void main(String[] args) throws AllegroGraphException {
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
AllegroGraph ts = ags.renew("datetime", AGPaths.TRIPLE_STORES);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
GregorianCalendar cal = new GregorianCalendar();
String date;
ts.registerNamespace("ex","http://example.org/");
cal.set(1932, Calendar.JANUARY, 1, 0, 0, 1);
date = sdf.format(cal.getTime());
ts.addStatement("!ex:person1","!ex:birthdate", ts.createEncodedLiteral(date,"date-time"));
cal.set(1948, Calendar.FEBRUARY, 29, 23, 59, 59);
date = sdf.format(cal.getTime());
ts.addStatement("!ex:person2","!ex:birthdate", ts.createEncodedLiteral(date,"date-time"));
cal.set(1968, Calendar.MARCH, 17, 8, 0, 0);
date = sdf.format(cal.getTime());
ts.addStatement("!ex:person3","!ex:birthdate", ts.createEncodedLiteral(date,"date-time"));
cal.set(1988, Calendar.APRIL, 3, 9, 0, 0);
date = sdf.format(cal.getTime());
ts.addStatement("!ex:person4","!ex:birthdate", ts.createEncodedLiteral(date,"date-time"));
cal.set(2007, Calendar.JUNE, 31, 12, 0, 0);
date = sdf.format(cal.getTime());
ts.addStatement("!ex:person5","!ex:birthdate", ts.createEncodedLiteral(date,"date-time"));
cal.set(1980, Calendar.JANUARY, 1, 0, 0, 0); date = sdf.format(cal.getTime());
Literal low = ts.createEncodedLiteral(date,"date-time");
cal.set(1989, Calendar.DECEMBER, 31, 23, 59, 59); date = sdf.format(cal.getTime());
Literal high = ts.createEncodedLiteral(date,"date-time");
System.out.println("Retrieving triples for birthdates in the 1980's:");
Cursor cc = ts.getStatements(null, "!ex:birthdate", low, high, null, null);
AGUtils.showTriples(cc);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next