Search in sources :

Example 11 with TemporalInterval

use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.

the class MongoTemporalIndexerIT method testQueryInstantAfterInterval.

/**
 * Test instant after given interval.
 * Instance {before, after, inside} given Interval
 */
@Test
public void testQueryInstantAfterInterval() throws IOException, QueryEvaluationException {
    try (MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
        tIndexer.setConf(conf);
        tIndexer.init();
        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
        // these should not match as they are not instances.
        tIndexer.storeStatement(convertStatement(spo_B03_E20));
        tIndexer.storeStatement(convertStatement(spo_B02_E30));
        tIndexer.storeStatement(convertStatement(spo_B02_E40));
        tIndexer.storeStatement(convertStatement(spo_B02_E31));
        tIndexer.storeStatement(convertStatement(spo_B30_E32));
        // seriesSpo[s] and seriesTs[s] are statements and instants for s seconds after the uniform time.
        // from 2 to 31 seconds
        final TemporalInterval searchAfterInterval = tvB02_E31;
        final int endingSeconds = 31;
        // 32,33,...,40 seconds.
        final int expectedResultCount = 9;
        for (int s = 0; s <= endingSeconds + expectedResultCount; s++) {
            // <== logic here
            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
        }
        CloseableIteration<Statement, QueryEvaluationException> iter;
        iter = tIndexer.queryInstantAfterInterval(searchAfterInterval, EMPTY_CONSTRAINTS);
        int count = 0;
        while (iter.hasNext()) {
            final Statement s = iter.next();
            // <== logic here
            final Statement nextExpectedStatement = seriesSpo[count + endingSeconds + 1];
            assertTrue("Should match: " + nextExpectedStatement + " == " + s, nextExpectedStatement.equals(s));
            count++;
        }
        assertEquals("Should find count of rows.", expectedResultCount, count);
    }
}
Also used : MongoTemporalIndexer(org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) TemporalInterval(org.apache.rya.indexing.TemporalInterval) Test(org.junit.Test)

Example 12 with TemporalInterval

use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.

the class TemporalMongoDBStorageStrategy method getTimeValue.

public DBObject getTimeValue(final String timeData) {
    final Matcher match = TemporalInstantRfc3339.PATTERN.matcher(timeData);
    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    if (match.find()) {
        final TemporalInterval date = TemporalInstantRfc3339.parseInterval(timeData);
        builder.add(INTERVAL_START, date.getHasBeginning().getAsDateTime().toDate());
        builder.add(INTERVAL_END, date.getHasEnd().getAsDateTime().toDate());
    } else {
        builder.add(INSTANT, TemporalInstantRfc3339.FORMATTER.parseDateTime(timeData).toDate());
    }
    return builder.get();
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) Matcher(java.util.regex.Matcher) TemporalInterval(org.apache.rya.indexing.TemporalInterval)

Example 13 with TemporalInterval

use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.

the class MongoGeoTemporalIndexer method updateEvent.

private void updateEvent(final RyaURI subject, final RyaStatement statement) throws IndexingException, ParseException {
    final EventStorage eventStore = events.get();
    checkState(events != null, "Must set this indexers configuration before storing statements.");
    new EventUpdater(eventStore).update(subject, old -> {
        final Event.Builder updated;
        if (!old.isPresent()) {
            updated = Event.builder().setSubject(subject);
        } else {
            updated = Event.builder(old.get());
        }
        final URI pred = statement.getObject().getDataType();
        if (pred.equals(GeoConstants.GEO_AS_WKT) || pred.equals(GeoConstants.GEO_AS_GML) || pred.equals(GeoConstants.XMLSCHEMA_OGC_WKT) || pred.equals(GeoConstants.XMLSCHEMA_OGC_GML)) {
            // is geo
            try {
                final Statement geoStatement = RyaToRdfConversions.convertStatement(statement);
                final Geometry geometry = GeoParseUtils.getGeometry(geoStatement, new GmlParser());
                updated.setGeometry(geometry);
            } catch (final ParseException e) {
                LOG.error(e.getMessage(), e);
            }
        } else {
            // is time
            final String dateTime = statement.getObject().getData();
            final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(dateTime);
            if (matcher.find()) {
                final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(dateTime);
                updated.setTemporalInterval(interval);
            } else {
                final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
                updated.setTemporalInstant(instant);
            }
        }
        return Optional.of(updated.build());
    });
}
Also used : Matcher(java.util.regex.Matcher) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) GmlParser(org.apache.rya.indexing.mongodb.geo.GmlParser) TemporalInstant(org.apache.rya.indexing.TemporalInstant) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Geometry(com.vividsolutions.jts.geom.Geometry) Event(org.apache.rya.indexing.geotemporal.model.Event) ParseException(com.vividsolutions.jts.io.ParseException) TemporalInterval(org.apache.rya.indexing.TemporalInterval) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage)

Example 14 with TemporalInterval

use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.

the class TemporalIntervalTest method keyBeginTest.

@Test
public void keyBeginTest() throws Exception {
    // 58 seconds, earlier
    TemporalInterval beginTI01 = new TemporalInterval(// 
    new TemporalInstantRfc3339(2015, 12, 30, 12, 59, 58), // 
    new TemporalInstantRfc3339(2016, 12, 30, 13, 00, 00));
    // 59 seconds, later
    TemporalInterval beginTI02 = new TemporalInterval(// 
    new TemporalInstantRfc3339(2015, 12, 30, 12, 59, 59), // 
    new TemporalInstantRfc3339(2016, 12, 30, 13, 00, 00));
    String key01b = Arrays.toString(beginTI01.getAsKeyBeginning());
    String key02b = Arrays.toString(beginTI02.getAsKeyBeginning());
    Assert.assertEquals("key02 is later so comparesTo = 1.", 1, key02b.compareTo(key01b));
    Assert.assertEquals("key01 is first so comparesTo = -1", -1, key01b.compareTo(key02b));
}
Also used : TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInterval(org.apache.rya.indexing.TemporalInterval) Test(org.junit.Test)

Example 15 with TemporalInterval

use of org.apache.rya.indexing.TemporalInterval in project incubator-rya by apache.

the class TemporalIntervalTest method infinitePastFutureAlwaysTest.

@Test
public void infinitePastFutureAlwaysTest() throws Exception {
    final TemporalInstant TestDateString = new TemporalInstantRfc3339(new DateTime("2015-01-01T01:59:59Z"));
    TemporalInterval tvFuture = new TemporalInterval(TestDateString, TemporalInstantRfc3339.getMaximumInstance());
    TemporalInterval tvPast = new TemporalInterval(TemporalInstantRfc3339.getMinimumInstance(), TestDateString);
    TemporalInterval tvAlways = new TemporalInterval(TemporalInstantRfc3339.getMinimumInstance(), TemporalInstantRfc3339.getMaximumInstance());
    Assert.assertTrue("The future is greater (starts after) than the past for compareTo().", tvFuture.compareTo(tvPast) > 0);
    Assert.assertTrue("The future is greater (starts after) than always for compareTo().", tvFuture.compareTo(tvAlways) > 0);
    Assert.assertTrue("The past is less (starts same, ends earlier) than always for compareTo().", tvFuture.compareTo(tvPast) > 0);
}
Also used : TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInstant(org.apache.rya.indexing.TemporalInstant) TemporalInterval(org.apache.rya.indexing.TemporalInterval) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

TemporalInterval (org.apache.rya.indexing.TemporalInterval)24 Test (org.junit.Test)16 TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)12 Statement (org.openrdf.model.Statement)11 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)10 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10 TemporalInstant (org.apache.rya.indexing.TemporalInstant)7 RyaStatement (org.apache.rya.api.domain.RyaStatement)6 MongoTemporalIndexer (org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer)5 DateTime (org.joda.time.DateTime)5 Matcher (java.util.regex.Matcher)4 IOException (java.io.IOException)3 RyaURI (org.apache.rya.api.domain.RyaURI)3 Event (org.apache.rya.indexing.geotemporal.model.Event)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 ParseException (com.vividsolutions.jts.io.ParseException)2 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)2 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)2 GmlParser (org.apache.rya.indexing.mongodb.geo.GmlParser)2 Literal (org.openrdf.model.Literal)2