Search in sources :

Example 6 with TemporalInstantRfc3339

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

the class EventQueryNode2IT method evaluate_variableSubject_existingBindingsetWrongFilters.

@Test
public void evaluate_variableSubject_existingBindingsetWrongFilters() throws Exception {
    final EventStorage storage = new MongoEventStorage(super.getMongoClient(), "testDB");
    RyaURI subject = new RyaURI("urn:event-1111");
    Geometry geo = GF.createPoint(new Coordinate(1, 1));
    final TemporalInstant temp = new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0);
    final Event event = Event.builder().setSubject(subject).setGeometry(geo).setTemporalInstant(temp).build();
    subject = new RyaURI("urn:event-2222");
    geo = GF.createPoint(new Coordinate(-10, -10));
    final Event otherEvent = Event.builder().setSubject(subject).setGeometry(geo).setTemporalInstant(temp).build();
    storage.create(event);
    storage.create(otherEvent);
    final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT ?event ?time ?point ?wkt " + "WHERE { " + "  ?event time:atTime ?time . " + "  ?event geo:asWKT ?wkt . " + "  FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + "  FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) " + "}";
    final EventQueryNode node = buildNode(storage, query);
    final MapBindingSet existingBindings = new MapBindingSet();
    existingBindings.addBinding("event", VF.createURI("urn:event-2222"));
    final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(existingBindings);
    final MapBindingSet expected = new MapBindingSet();
    expected.addBinding("wkt", VF.createLiteral("POINT (-1 -1)"));
    expected.addBinding("time", VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()));
    assertFalse(rez.hasNext());
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Coordinate(com.vividsolutions.jts.geom.Coordinate) MapBindingSet(org.openrdf.query.impl.MapBindingSet) MongoEventStorage(org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage) MongoEventStorage(org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 7 with TemporalInstantRfc3339

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

the class MongoIndexerDeleteIT method populateRya.

private void populateRya(final SailRepositoryConnection conn) throws Exception {
    final ValueFactory VF = new ValueFactoryImpl();
    // geo 2x2 points
    final GeometryFactory GF = new GeometryFactory();
    for (int x = 0; x <= 1; x++) {
        for (int y = 0; y <= 1; y++) {
            final Geometry geo = GF.createPoint(new Coordinate(x + .5, y + .5));
            final RyaStatement stmnt = statement(geo);
            final Statement statement = RyaToRdfConversions.convertStatement(stmnt);
            conn.add(statement);
        }
    }
    // freetext
    final URI person = VF.createURI("http://example.org/ontology/Person");
    String uuid;
    uuid = "urn:people";
    conn.add(VF.createURI(uuid), RDF.TYPE, person);
    conn.add(VF.createURI(uuid), RDFS.LABEL, VF.createLiteral("Alice Palace Hose", VF.createURI("http://www.w3.org/2001/XMLSchema#string")));
    conn.add(VF.createURI(uuid), RDFS.LABEL, VF.createLiteral("Bob Snob Hose", "en"));
    // temporal
    final TemporalInstant instant = new TemporalInstantRfc3339(1, 2, 3, 4, 5, 6);
    conn.add(VF.createURI("foo:time"), VF.createURI("Property:atTime"), VF.createLiteral(instant.toString()));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactory(org.openrdf.model.ValueFactory) TemporalInstant(org.apache.rya.indexing.TemporalInstant) URI(org.openrdf.model.URI)

Example 8 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 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 9 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 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 10 with TemporalInstantRfc3339

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

the class GeoTemporalProviderTest method twoPatternsTwoFilters_test.

/*
     * Simplest Happy Path test
     */
@Test
public void twoPatternsTwoFilters_test() throws Exception {
    final ValueFactory vf = new ValueFactoryImpl();
    final Value geo = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
    final Value temp = vf.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString());
    final URI tempPred = vf.createURI(URI_PROPERTY_AT_TIME);
    final String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" + "PREFIX time: <tag:rya-rdf.org,2015:temporal#>" + "SELECT * WHERE { " + "?subj <" + tempPred + "> ?time ." + "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " + " FILTER(geos:sfContains(?loc, " + geo + ")) . " + " FILTER(time:equals(?time, " + temp + ")) . " + "}";
    final QuerySegment<EventQueryNode> node = getQueryNode(query);
    final List<EventQueryNode> nodes = provider.getExternalSets(node);
    assertEquals(1, nodes.size());
}
Also used : ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Value(org.openrdf.model.Value) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) ValueFactory(org.openrdf.model.ValueFactory) EventQueryNode(org.apache.rya.indexing.geotemporal.model.EventQueryNode) URI(org.openrdf.model.URI) Test(org.junit.Test)

Aggregations

TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)34 Test (org.junit.Test)26 TemporalInstant (org.apache.rya.indexing.TemporalInstant)21 RyaURI (org.apache.rya.api.domain.RyaURI)15 Geometry (com.vividsolutions.jts.geom.Geometry)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)12 TemporalInterval (org.apache.rya.indexing.TemporalInterval)12 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)11 URI (org.openrdf.model.URI)11 Event (org.apache.rya.indexing.geotemporal.model.Event)9 Value (org.openrdf.model.Value)9 ValueFactory (org.openrdf.model.ValueFactory)9 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)9 EventQueryNode (org.apache.rya.indexing.geotemporal.model.EventQueryNode)7 DateTime (org.joda.time.DateTime)5 MongoEventStorage (org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage)4 BindingSet (org.openrdf.query.BindingSet)4 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)4 MapBindingSet (org.openrdf.query.impl.MapBindingSet)4 IOException (java.io.IOException)3