Search in sources :

Example 6 with TemporalInstant

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

the class RyaOutputFormatTest method testTemporalIndexing.

@Test
public void testTemporalIndexing() throws Exception {
    final TemporalInstant[] instants = { new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 01), new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 02), new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 03), new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 03) };
    final Statement[] statements = new Statement[instants.length];
    RyaOutputFormat.setCoreTablesEnabled(job, false);
    RyaOutputFormat.setFreeTextEnabled(job, false);
    RyaOutputFormat.setTemporalEnabled(job, true);
    RyaOutputFormat.setEntityEnabled(job, false);
    final ValueFactory vf = new ValueFactoryImpl();
    for (int i = 0; i < instants.length; i++) {
        final RyaType time = RdfToRyaConversions.convertLiteral(vf.createLiteral(instants[i].toString()));
        final RyaStatement input = RyaStatement.builder().setSubject(new RyaURI(GRAPH + ":s")).setPredicate(new RyaURI(GRAPH + ":p")).setObject(time).build();
        write(input);
        statements[i] = RyaToRdfConversions.convertStatement(input);
    }
    final AccumuloTemporalIndexer temporal = new AccumuloTemporalIndexer();
    temporal.setConf(conf);
    Connector connector = ConfigUtils.getConnector(conf);
    MultiTableBatchWriter mtbw = connector.createMultiTableBatchWriter(new BatchWriterConfig());
    temporal.setConnector(connector);
    temporal.setMultiTableBatchWriter(mtbw);
    temporal.init();
    final Set<Statement> empty = new HashSet<>();
    final Set<Statement> head = new HashSet<>();
    final Set<Statement> tail = new HashSet<>();
    head.add(statements[0]);
    tail.add(statements[2]);
    tail.add(statements[3]);
    Assert.assertEquals(empty, getSet(temporal.queryInstantBeforeInstant(instants[0], new StatementConstraints())));
    Assert.assertEquals(empty, getSet(temporal.queryInstantAfterInstant(instants[3], new StatementConstraints())));
    Assert.assertEquals(head, getSet(temporal.queryInstantBeforeInstant(instants[1], new StatementConstraints())));
    Assert.assertEquals(tail, getSet(temporal.queryInstantAfterInstant(instants[1], new StatementConstraints())));
    temporal.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactory(org.openrdf.model.ValueFactory) TemporalInstant(org.apache.rya.indexing.TemporalInstant) RyaType(org.apache.rya.api.domain.RyaType) RyaURI(org.apache.rya.api.domain.RyaURI) StatementConstraints(org.apache.rya.indexing.StatementConstraints) AccumuloTemporalIndexer(org.apache.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with TemporalInstant

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

the class EventQueryNode method evaluate.

@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings) throws QueryEvaluationException {
    final List<BindingSet> list = new ArrayList<>();
    try {
        final Collection<Event> searchEvents;
        final String subj;
        // if the provided binding set has the subject already, set it to the constant subject.
        if (!subjectConstant.isPresent() && bindings.hasBinding(subjectVar.get())) {
            subjectConstant = Optional.of(bindings.getValue(subjectVar.get()).stringValue());
        } else if (bindings.size() != 0) {
            list.add(bindings);
        }
        // If the subject needs to be filled in, check if the subject variable is in the binding set.
        if (subjectConstant.isPresent()) {
            // if it is, fetch that value and then fetch the entity for the subject.
            subj = subjectConstant.get();
            searchEvents = eventStore.search(Optional.of(new RyaURI(subj)), Optional.of(geoFilters), Optional.of(temporalFilters));
        } else {
            searchEvents = eventStore.search(Optional.empty(), Optional.of(geoFilters), Optional.of(temporalFilters));
        }
        for (final Event event : searchEvents) {
            final MapBindingSet resultSet = new MapBindingSet();
            if (event.getGeometry().isPresent()) {
                final Geometry geo = event.getGeometry().get();
                final Value geoValue = ValueFactoryImpl.getInstance().createLiteral(geo.toText());
                final Var geoObj = geoPattern.getObjectVar();
                resultSet.addBinding(geoObj.getName(), geoValue);
            }
            final Value temporalValue;
            if (event.isInstant() && event.getInstant().isPresent()) {
                final Optional<TemporalInstant> opt = event.getInstant();
                DateTime dt = opt.get().getAsDateTime();
                dt = dt.toDateTime(DateTimeZone.UTC);
                final String str = dt.toString(TemporalInstantRfc3339.FORMATTER);
                temporalValue = ValueFactoryImpl.getInstance().createLiteral(str);
            } else if (event.getInterval().isPresent()) {
                temporalValue = ValueFactoryImpl.getInstance().createLiteral(event.getInterval().get().getAsPair());
            } else {
                temporalValue = null;
            }
            if (temporalValue != null) {
                final Var temporalObj = temporalPattern.getObjectVar();
                resultSet.addBinding(temporalObj.getName(), temporalValue);
            }
            list.add(resultSet);
        }
    } catch (final ObjectStorageException e) {
        throw new QueryEvaluationException("Failed to evaluate the binding set", e);
    }
    return new CollectionIteration<>(list);
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) ObjectStorageException(org.apache.rya.indexing.mongodb.update.RyaObjectStorage.ObjectStorageException) TemporalInstant(org.apache.rya.indexing.TemporalInstant) DateTime(org.joda.time.DateTime) Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) CollectionIteration(org.openrdf.query.algebra.evaluation.iterator.CollectionIteration) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Value(org.openrdf.model.Value) MapBindingSet(org.openrdf.query.impl.MapBindingSet)

Example 8 with TemporalInstant

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

the class EventDocumentConverterTest method to_and_from_document.

@Test
public void to_and_from_document() throws DocumentConverterException {
    final Geometry geo = GF.createPoint(new Coordinate(10, 10));
    final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
    // An Event that will be stored.
    final Event event = Event.builder().setSubject(new RyaURI("urn:event/001")).setGeometry(geo).setTemporalInstant(instant).build();
    final Document document = new EventDocumentConverter().toDocument(event);
    // Convert the Document back into an Event.
    final Event converted = new EventDocumentConverter().fromDocument(document);
    // Ensure the original matches the round trip converted Event.
    assertEquals(event, converted);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Event(org.apache.rya.indexing.geotemporal.model.Event) EventDocumentConverter(org.apache.rya.indexing.geotemporal.mongo.EventDocumentConverter) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Document(org.bson.Document) Test(org.junit.Test)

Example 9 with TemporalInstant

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

the class MongoEventStorageIT method create_and_get.

@Test
public void create_and_get() throws Exception {
    final Geometry geo = GF.createPoint(new Coordinate(10, 10));
    final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
    // An Event that will be stored.
    final Event event = Event.builder().setSubject(new RyaURI("urn:event/001")).setGeometry(geo).setTemporalInstant(instant).build();
    // Create it.
    final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    storage.create(event);
    // Get it.
    final Optional<Event> storedEvent = storage.get(new RyaURI("urn:event/001"));
    // Verify the correct value was returned.
    assertEquals(event, storedEvent.get());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Event(org.apache.rya.indexing.geotemporal.model.Event) TemporalInstant(org.apache.rya.indexing.TemporalInstant) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 10 with TemporalInstant

use of org.apache.rya.indexing.TemporalInstant 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

TemporalInstant (org.apache.rya.indexing.TemporalInstant)22 TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)21 RyaURI (org.apache.rya.api.domain.RyaURI)15 Geometry (com.vividsolutions.jts.geom.Geometry)14 Test (org.junit.Test)14 Coordinate (com.vividsolutions.jts.geom.Coordinate)12 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)11 Event (org.apache.rya.indexing.geotemporal.model.Event)9 TemporalInterval (org.apache.rya.indexing.TemporalInterval)7 DateTime (org.joda.time.DateTime)5 BindingSet (org.openrdf.query.BindingSet)5 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)5 MapBindingSet (org.openrdf.query.impl.MapBindingSet)5 ArrayList (java.util.ArrayList)4 MongoEventStorage (org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage)4 IOException (java.io.IOException)3 Matcher (java.util.regex.Matcher)3 RyaStatement (org.apache.rya.api.domain.RyaStatement)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 ParseException (com.vividsolutions.jts.io.ParseException)2