use of org.apache.rya.indexing.geotemporal.storage.EventStorage in project incubator-rya by apache.
the class MongoGeoTemporalIndexIT method ensureInEventStore_Test.
@Test
public void ensureInEventStore_Test() throws Exception {
final Sail sail = GeoRyaSailFactory.getInstance(conf);
final SailRepository repo = new SailRepository(sail);
try (final MongoGeoTemporalIndexer indexer = new MongoGeoTemporalIndexer()) {
indexer.setConf(conf);
indexer.init();
addStatements(repo.getConnection());
final EventStorage events = indexer.getEventStorage();
final RyaURI subject = new RyaURI("urn:event1");
final Optional<Event> event = events.get(subject);
assertTrue(event.isPresent());
} finally {
sail.shutDown();
}
}
use of org.apache.rya.indexing.geotemporal.storage.EventStorage in project incubator-rya by apache.
the class EventQueryNode2IT method evaluate_variableSubject.
@Test
public void evaluate_variableSubject() 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(-1, -1));
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 CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(new MapBindingSet());
final MapBindingSet expected1 = new MapBindingSet();
expected1.addBinding("wkt", VF.createLiteral("POINT (1 1)"));
expected1.addBinding("time", VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()));
final MapBindingSet expected2 = new MapBindingSet();
expected2.addBinding("wkt", VF.createLiteral("POINT (-1 -1)"));
expected2.addBinding("time", VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()));
final List<BindingSet> actual = new ArrayList<>();
while (rez.hasNext()) {
actual.add(rez.next());
}
assertEquals(expected1, actual.get(0));
assertEquals(expected2, actual.get(1));
assertEquals(2, actual.size());
}
use of org.apache.rya.indexing.geotemporal.storage.EventStorage 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());
}
use of org.apache.rya.indexing.geotemporal.storage.EventStorage in project incubator-rya by apache.
the class MongoGeoTemporalIndexerIT method ensureEvent.
@Test
public void ensureEvent() throws Exception {
final RyaStatement geoStmnt = statement(point(0, 0));
final RyaStatement timeStmnt = statement(makeInstant(0));
final EventStorage store = indexer.getEventStorage();
indexer.storeStatement(geoStmnt);
Optional<Event> evnt = store.get(geoStmnt.getSubject());
assertTrue(evnt.isPresent());
Event expected = Event.builder().setSubject(geoStmnt.getSubject()).setGeometry(point(0, 0)).build();
assertEquals(expected, evnt.get());
indexer.storeStatement(timeStmnt);
evnt = store.get(timeStmnt.getSubject());
assertTrue(evnt.isPresent());
expected = Event.builder().setSubject(geoStmnt.getSubject()).setGeometry(point(0, 0)).setTemporalInstant(makeInstant(0)).build();
assertEquals(expected, evnt.get());
indexer.deleteStatement(geoStmnt);
evnt = store.get(timeStmnt.getSubject());
assertTrue(evnt.isPresent());
expected = Event.builder().setSubject(timeStmnt.getSubject()).setTemporalInstant(makeInstant(0)).build();
assertEquals(expected, evnt.get());
indexer.deleteStatement(timeStmnt);
evnt = store.get(timeStmnt.getSubject());
assertTrue(evnt.isPresent());
expected = Event.builder().setSubject(timeStmnt.getSubject()).build();
assertEquals(expected, evnt.get());
}
use of org.apache.rya.indexing.geotemporal.storage.EventStorage 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());
});
}
Aggregations