use of org.apache.rya.api.functions.DateTimeWithinPeriod in project incubator-rya by apache.
the class QueryIT method dateTimeWithinNow.
@Test
public void dateTimeWithinNow() throws Exception {
final ValueFactory vf = new ValueFactoryImpl();
final DatatypeFactory dtf = DatatypeFactory.newInstance();
FunctionRegistry.getInstance().add(new DateTimeWithinPeriod());
final String sparql = "PREFIX fn: <" + FN.NAMESPACE + ">" + "SELECT ?event ?startTime WHERE { ?event <uri:startTime> ?startTime. " + "FILTER(fn:dateTimeWithin(?startTime, NOW(), 30, <" + OWLTime.SECONDS_URI + "> ))}";
final ZonedDateTime zTime = ZonedDateTime.now();
final String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
final ZonedDateTime zTime1 = zTime.minusSeconds(30);
final String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
final Literal lit = vf.createLiteral(dtf.newXMLGregorianCalendar(time));
final Literal lit1 = vf.createLiteral(dtf.newXMLGregorianCalendar(time1));
// Create the Statements that will be loaded into Rya.
final Collection<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("uri:event1"), vf.createURI("uri:startTime"), lit), vf.createStatement(vf.createURI("uri:event2"), vf.createURI("uri:startTime"), lit1));
// Create the expected results of the SPARQL query once the PCJ has been computed.
final Set<BindingSet> expectedResults = new HashSet<>();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("event", vf.createURI("uri:event1"));
bs.addBinding("startTime", lit);
expectedResults.add(bs);
// Verify the end results of the query match the expected results.
runTest(sparql, statements, expectedResults, ExportStrategy.RYA);
}
use of org.apache.rya.api.functions.DateTimeWithinPeriod in project incubator-rya by apache.
the class QueryIT method dateTimeWithin.
@Test
public void dateTimeWithin() throws Exception {
final ValueFactory vf = new ValueFactoryImpl();
final DatatypeFactory dtf = DatatypeFactory.newInstance();
FunctionRegistry.getInstance().add(new DateTimeWithinPeriod());
final String sparql = "PREFIX fn: <" + FN.NAMESPACE + ">" + "SELECT ?event ?startTime ?endTime WHERE { ?event <uri:startTime> ?startTime; <uri:endTime> ?endTime. " + "FILTER(fn:dateTimeWithin(?startTime, ?endTime, 2,<" + OWLTime.HOURS_URI + "> ))}";
final ZonedDateTime zTime = ZonedDateTime.now();
final String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
final ZonedDateTime zTime1 = zTime.minusHours(1);
final String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
final ZonedDateTime zTime2 = zTime.minusHours(2);
final String time2 = zTime2.format(DateTimeFormatter.ISO_INSTANT);
final Literal lit = vf.createLiteral(dtf.newXMLGregorianCalendar(time));
final Literal lit1 = vf.createLiteral(dtf.newXMLGregorianCalendar(time1));
final Literal lit2 = vf.createLiteral(dtf.newXMLGregorianCalendar(time2));
// Create the Statements that will be loaded into Rya.
final Collection<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("uri:event1"), vf.createURI("uri:startTime"), lit), vf.createStatement(vf.createURI("uri:event1"), vf.createURI("uri:endTime"), lit1), vf.createStatement(vf.createURI("uri:event2"), vf.createURI("uri:startTime"), lit), vf.createStatement(vf.createURI("uri:event2"), vf.createURI("uri:endTime"), lit2));
// Create the expected results of the SPARQL query once the PCJ has been computed.
final Set<BindingSet> expectedResults = new HashSet<>();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("event", vf.createURI("uri:event1"));
bs.addBinding("startTime", lit);
bs.addBinding("endTime", lit1);
expectedResults.add(bs);
// Verify the end results of the query match the expected results.
runTest(sparql, statements, expectedResults, ExportStrategy.RYA);
}
Aggregations