use of org.apache.rya.api.domain.RyaIRI 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 RyaIRI subject = new RyaIRI("urn:event1");
final Optional<Event> event = events.get(subject);
assertTrue(event.isPresent());
} finally {
sail.shutDown();
}
}
use of org.apache.rya.api.domain.RyaIRI 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");
RyaIRI subject = new RyaIRI("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 RyaIRI("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.createIRI("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.api.domain.RyaIRI 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");
RyaIRI subject = new RyaIRI("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 RyaIRI("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.api.domain.RyaIRI in project incubator-rya by apache.
the class TestUtils method createRyaStatement.
/**
* Creates a {@link RyaStatement} from the specified subject, predicate, and object.
* @param subject the subject.
* @param predicate the predicate.
* @param object the object.
* @param date the {@link Date} to use for the key's timestamp.
* @return the {@link RyaStatement}.
*/
public static RyaStatement createRyaStatement(final String subject, final String predicate, final String object, final Date date) {
final RyaIRI subjectIri = createRyaIri(subject);
final RyaIRI predicateIri = createRyaIri(predicate);
final RyaIRI objectIri = createRyaIri(object);
final RyaStatement ryaStatement = new RyaStatement(subjectIri, predicateIri, objectIri);
if (date != null) {
ryaStatement.setTimestamp(date.getTime());
}
return ryaStatement;
}
use of org.apache.rya.api.domain.RyaIRI in project incubator-rya by apache.
the class InputIT method streamedResults.
/**
* Ensure streamed matches are included in the result.
*/
@Test
public void streamedResults() throws Exception {
// A query that finds people who talk to Eve and work at Chipotle.
final String sparql = "SELECT ?x WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://Chipotle>." + "}";
// Triples that will be streamed into Fluo after the PCJ has been created.
final Set<RyaStatement> streamedTriples = Sets.newHashSet(new RyaStatement(new RyaIRI("http://Alice"), new RyaIRI("http://talksTo"), new RyaIRI("http://Eve")), new RyaStatement(new RyaIRI("http://Bob"), new RyaIRI("http://talksTo"), new RyaIRI("http://Eve")), new RyaStatement(new RyaIRI("http://Charlie"), new RyaIRI("http://talksTo"), new RyaIRI("http://Eve")), new RyaStatement(new RyaIRI("http://Eve"), new RyaIRI("http://helps"), new RyaIRI("http://Kevin")), new RyaStatement(new RyaIRI("http://Bob"), new RyaIRI("http://worksAt"), new RyaIRI("http://Chipotle")), new RyaStatement(new RyaIRI("http://Charlie"), new RyaIRI("http://worksAt"), new RyaIRI("http://Chipotle")), new RyaStatement(new RyaIRI("http://Eve"), new RyaIRI("http://worksAt"), new RyaIRI("http://Chipotle")), new RyaStatement(new RyaIRI("http://David"), new RyaIRI("http://worksAt"), new RyaIRI("http://Chipotle")));
// The expected results of the SPARQL query once the PCJ has been computed.
final ValueFactory vf = SimpleValueFactory.getInstance();
final Set<BindingSet> expected = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("x", vf.createIRI("http://Bob"));
expected.add(bs);
bs = new MapBindingSet();
bs.addBinding("x", vf.createIRI("http://Charlie"));
expected.add(bs);
// Create the PCJ table.
final Connector accumuloConn = super.getAccumuloConnector();
final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName());
final String pcjId = pcjStorage.createPcj(sparql);
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
// Tell the Fluo app to maintain the PCJ.
new CreateFluoPcj().withRyaIntegration(pcjId, pcjStorage, fluoClient, accumuloConn, getRyaInstanceName());
// Ensure the query has no results yet.
super.getMiniFluo().waitForObservers();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
assertFalse(resultsIt.hasNext());
}
// Stream the data into Fluo.
new InsertTriples().insert(fluoClient, streamedTriples, Optional.absent());
// Verify the end results of the query match the expected results.
super.getMiniFluo().waitForObservers();
final HashSet<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertEquals(expected, results);
}
}
Aggregations