Search in sources :

Example 71 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class RyaExportIT method resultsExported.

@Test
public void resultsExported() throws Exception {
    final String sparql = "SELECT ?customer ?worker ?city " + "{ " + "FILTER(?customer = <http://Alice>) " + "FILTER(?city = <http://London>) " + "?customer <http://talksTo> ?worker. " + "?worker <http://livesIn> ?city. " + "?worker <http://worksAt> <http://Chipotle>. " + "}";
    // Triples that will be streamed into Fluo after the PCJ has been created.
    final ValueFactory vf = new ValueFactoryImpl();
    final Set<RyaStatement> streamedTriples = Sets.newHashSet(new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://talksTo"), new RyaURI("http://Bob")), new RyaStatement(new RyaURI("http://Bob"), new RyaURI("http://livesIn"), new RyaURI("http://London")), new RyaStatement(new RyaURI("http://Bob"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")), new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://talksTo"), new RyaURI("http://Charlie")), new RyaStatement(new RyaURI("http://Charlie"), new RyaURI("http://livesIn"), new RyaURI("http://London")), new RyaStatement(new RyaURI("http://Charlie"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")), new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://talksTo"), new RyaURI("http://David")), new RyaStatement(new RyaURI("http://David"), new RyaURI("http://livesIn"), new RyaURI("http://London")), new RyaStatement(new RyaURI("http://David"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")), new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://talksTo"), new RyaURI("http://Eve")), new RyaStatement(new RyaURI("http://Eve"), new RyaURI("http://livesIn"), new RyaURI("http://Leeds")), new RyaStatement(new RyaURI("http://Eve"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")), new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://talksTo"), new RyaURI("http://Alice")), new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://livesIn"), new RyaURI("http://London")), new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")));
    // The expected results of the SPARQL query once the PCJ has been computed.
    final Set<BindingSet> expected = new HashSet<>();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("customer", vf.createURI("http://Alice"));
    bs.addBinding("worker", vf.createURI("http://Bob"));
    bs.addBinding("city", vf.createURI("http://London"));
    expected.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("customer", vf.createURI("http://Alice"));
    bs.addBinding("worker", vf.createURI("http://Charlie"));
    bs.addBinding("city", vf.createURI("http://London"));
    expected.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("customer", vf.createURI("http://Alice"));
    bs.addBinding("worker", vf.createURI("http://David"));
    bs.addBinding("city", vf.createURI("http://London"));
    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());
        // Stream the data into Fluo.
        new InsertTriples().insert(fluoClient, streamedTriples, Optional.<String>absent());
        // Fetch the exported results from Accumulo once the observers finish working.
        super.getMiniFluo().waitForObservers();
        // Fetch expected results from the PCJ table that is in Accumulo.
        final Set<BindingSet> results = Sets.newHashSet(pcjStorage.listResults(pcjId));
        // Verify the end results of the query match the expected results.
        assertEquals(expected, results);
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) Connector(org.apache.accumulo.core.client.Connector) FluoClient(org.apache.fluo.api.client.FluoClient) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) InsertTriples(org.apache.rya.indexing.pcj.fluo.api.InsertTriples) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) RyaStatement(org.apache.rya.api.domain.RyaStatement) CreateFluoPcj(org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj) ValueFactory(org.openrdf.model.ValueFactory) RyaURI(org.apache.rya.api.domain.RyaURI) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 72 with RyaURI

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

Example 73 with RyaURI

use of org.apache.rya.api.domain.RyaURI 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());
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) ArrayList(java.util.ArrayList) 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 74 with RyaURI

use of org.apache.rya.api.domain.RyaURI 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 75 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class DuplicateDataDetector method compareEntities.

/**
 * Compares two entities to determine if they have nearly identical data.
 * @param entity1 the first {@link Entity}. (not {@code null})
 * @param entity2 the second {@link Entity}. (not {@code null})
 * @return {@code true} if the two entities have nearly identical data.
 * {@code false} otherwise.
 * @throws SmartUriException
 */
public boolean compareEntities(final Entity entity1, final Entity entity2) throws SmartUriException {
    requireNonNull(entity1);
    requireNonNull(entity2);
    boolean allValuesNearlyEqual = true;
    final List<RyaURI> types1 = entity1.getExplicitTypeIds();
    final List<RyaURI> types2 = entity2.getExplicitTypeIds();
    final boolean doBothHaveSameTypes = types1.containsAll(types2);
    if (!doBothHaveSameTypes) {
        return false;
    }
    for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> entry : entity1.getProperties().entrySet()) {
        final RyaURI typeIdUri = entry.getKey();
        for (final Entry<RyaURI, Property> typeProperty : entry.getValue().entrySet()) {
            final RyaURI propertyNameUri = typeProperty.getKey();
            final Property property1 = typeProperty.getValue();
            final Optional<Property> p2 = entity2.lookupTypeProperty(typeIdUri, propertyNameUri);
            if (p2.isPresent()) {
                final Property property2 = p2.get();
                final RyaType value1 = property1.getValue();
                final RyaType value2 = property2.getValue();
                final String data1 = value1.getData();
                final String data2 = value2.getData();
                final URI xmlSchemaUri1 = value1.getDataType();
                final ApproxEqualsDetector<?> approxEqualsDetector = uriMap.get(xmlSchemaUri1);
                if (approxEqualsDetector == null) {
                    throw new SmartUriException("No appropriate detector found for the type: " + xmlSchemaUri1);
                }
                final boolean approxEquals = approxEqualsDetector.areApproxEquals(data1, data2);
                if (!approxEquals) {
                    allValuesNearlyEqual = false;
                    break;
                }
            } else {
                allValuesNearlyEqual = false;
                break;
            }
        }
        if (!allValuesNearlyEqual) {
            break;
        }
    }
    return allValuesNearlyEqual;
}
Also used : SmartUriException(org.apache.rya.indexing.smarturi.SmartUriException) RyaType(org.apache.rya.api.domain.RyaType) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) ImmutableMap(com.google.common.collect.ImmutableMap) RyaURI(org.apache.rya.api.domain.RyaURI) Property(org.apache.rya.indexing.entity.model.Property)

Aggregations

RyaURI (org.apache.rya.api.domain.RyaURI)287 Test (org.junit.Test)190 RyaStatement (org.apache.rya.api.domain.RyaStatement)183 RyaType (org.apache.rya.api.domain.RyaType)146 BindingSet (org.openrdf.query.BindingSet)56 ArrayList (java.util.ArrayList)52 StatementPattern (org.openrdf.query.algebra.StatementPattern)50 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)49 HashSet (java.util.HashSet)43 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)43 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)42 ParsedQuery (org.openrdf.query.parser.ParsedQuery)42 SPARQLParser (org.openrdf.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 URIImpl (org.openrdf.model.impl.URIImpl)25 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)22 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)21 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)21