Search in sources :

Example 1 with RyaIRI

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();
    }
}
Also used : MongoGeoTemporalIndexer(org.apache.rya.indexing.geotemporal.mongo.MongoGeoTemporalIndexer) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) RyaIRI(org.apache.rya.api.domain.RyaIRI) Sail(org.eclipse.rdf4j.sail.Sail) Event(org.apache.rya.indexing.geotemporal.model.Event) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 2 with RyaIRI

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());
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) RyaIRI(org.apache.rya.api.domain.RyaIRI) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Geometry(com.vividsolutions.jts.geom.Geometry) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Coordinate(com.vividsolutions.jts.geom.Coordinate) MapBindingSet(org.eclipse.rdf4j.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 3 with RyaIRI

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());
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) RyaIRI(org.apache.rya.api.domain.RyaIRI) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) ArrayList(java.util.ArrayList) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Geometry(com.vividsolutions.jts.geom.Geometry) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Coordinate(com.vividsolutions.jts.geom.Coordinate) MapBindingSet(org.eclipse.rdf4j.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 4 with RyaIRI

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;
}
Also used : RyaIRI(org.apache.rya.api.domain.RyaIRI) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Example 5 with RyaIRI

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);
    }
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) Connector(org.apache.accumulo.core.client.Connector) FluoClient(org.apache.fluo.api.client.FluoClient) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) RyaIRI(org.apache.rya.api.domain.RyaIRI) InsertTriples(org.apache.rya.indexing.pcj.fluo.api.InsertTriples) RyaStatement(org.apache.rya.api.domain.RyaStatement) CreateFluoPcj(org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

RyaIRI (org.apache.rya.api.domain.RyaIRI)291 Test (org.junit.Test)191 RyaStatement (org.apache.rya.api.domain.RyaStatement)187 RyaType (org.apache.rya.api.domain.RyaType)148 BindingSet (org.eclipse.rdf4j.query.BindingSet)56 ArrayList (java.util.ArrayList)53 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)50 QueryBindingSet (org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet)49 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)46 HashSet (java.util.HashSet)43 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)42 ParsedQuery (org.eclipse.rdf4j.query.parser.ParsedQuery)42 SPARQLParser (org.eclipse.rdf4j.query.parser.sparql.SPARQLParser)42 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)35 Entity (org.apache.rya.indexing.entity.model.Entity)30 Property (org.apache.rya.indexing.entity.model.Property)28 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)22 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)22 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)21 Map (java.util.Map)20