Search in sources :

Example 16 with StatementConstraints

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

the class GeoWaveIndexerTest method testDcSearchWithContext.

@Test
public void testDcSearchWithContext() throws Exception {
    // test a ring around dc
    try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) {
        f.setConf(conf);
        f.purge(conf);
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        // query with correct context
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
        // query with wrong context
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) StatementConstraints(org.apache.rya.indexing.StatementConstraints) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Example 17 with StatementConstraints

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

the class MongoGeoIndexerIT method testDcSearchWithSubject.

@Test
public void testDcSearchWithSubject() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        // query with correct subject
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
        // query with wrong subject
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) MongoGeoIndexer(org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) StatementConstraints(org.apache.rya.indexing.StatementConstraints) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Example 18 with StatementConstraints

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

the class MongoGeoIndexerIT method testDcSearchWithPredicate.

@Test
public void testDcSearchWithPredicate() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        // query with correct Predicate
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));
        // query with wrong predicate
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createURI("other:pred"))))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) MongoGeoIndexer(org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) StatementConstraints(org.apache.rya.indexing.StatementConstraints) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Example 19 with StatementConstraints

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

the class MongoTemporalIndexerIT method testQueryWithMultiplePredicates.

/**
 * Test instant after a given instant WITH two different predicates as constraints.
 */
@Test
public void testQueryWithMultiplePredicates() throws IOException, QueryEvaluationException {
    try (MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
        tIndexer.setConf(conf);
        tIndexer.init();
        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
        // these should not match as they are not instances.
        tIndexer.storeStatement(convertStatement(spo_B03_E20));
        tIndexer.storeStatement(convertStatement(spo_B02_E30));
        tIndexer.storeStatement(convertStatement(spo_B02_E40));
        tIndexer.storeStatement(convertStatement(spo_B02_E31));
        tIndexer.storeStatement(convertStatement(spo_B30_E32));
        // seriesSpo[s] and seriesTs[s] are statements and instant for s seconds after the uniform time.
        final int searchForSeconds = 4;
        final int expectedResultCount = 9;
        for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) {
            // <== logic here
            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
        }
        final ValueFactory vf = new ValueFactoryImpl();
        // this one to ignore.
        final URI pred3_CIRCA_ = vf.createURI(URI_PROPERTY_CIRCA);
        final URI pred2_eventTime = vf.createURI(URI_PROPERTY_EVENT_TIME);
        final URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
        // add the predicate = EventTime ; Store in an array for verification.
        final Statement[] SeriesTs_EventTime = new Statement[expectedResultCount + 1];
        for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) {
            // <== logic here
            final Statement statement = new StatementImpl(vf.createURI("foo:EventTimeSubj0" + s), pred2_eventTime, vf.createLiteral(seriesTs[s].getAsReadable()));
            tIndexer.storeStatement(convertStatement(statement));
            if (s > searchForSeconds) {
                SeriesTs_EventTime[s - searchForSeconds - 1] = statement;
            }
        }
        // add the predicate = CIRCA ; to be ignored because it is not in the constraints.
        for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) {
            // <== logic here
            final Statement statement = new StatementImpl(vf.createURI("foo:CircaEventSubj0" + s), pred3_CIRCA_, vf.createLiteral(seriesTs[s].getAsReadable()));
            tIndexer.storeStatement(convertStatement(statement));
        }
        CloseableIteration<Statement, QueryEvaluationException> iter;
        final StatementConstraints constraints = new StatementConstraints();
        constraints.setPredicates(new HashSet<>(Arrays.asList(pred2_eventTime, pred1_atTime)));
        // EMPTY_CONSTRAINTS);//
        iter = tIndexer.queryInstantAfterInstant(seriesTs[searchForSeconds], constraints);
        int count_AtTime = 0;
        int count_EventTime = 0;
        while (iter.hasNext()) {
            final Statement s = iter.next();
            // <== logic here
            final Statement nextExpectedStatement = seriesSpo[searchForSeconds + count_AtTime + 1];
            if (s.getPredicate().equals(pred1_atTime)) {
                assertTrue("Should match atTime: " + nextExpectedStatement + " == " + s, nextExpectedStatement.equals(s));
                count_AtTime++;
            } else if (s.getPredicate().equals(pred2_eventTime)) {
                assertTrue("Should match eventTime: " + SeriesTs_EventTime[count_EventTime] + " == " + s, SeriesTs_EventTime[count_EventTime].equals(s));
                count_EventTime++;
            } else {
                assertTrue("This predicate should not be returned: " + s, false);
            }
        }
        assertEquals("Should find count of atTime    rows.", expectedResultCount, count_AtTime);
        assertEquals("Should find count of eventTime rows.", expectedResultCount, count_EventTime);
    }
}
Also used : StatementConstraints(org.apache.rya.indexing.StatementConstraints) MongoTemporalIndexer(org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Test(org.junit.Test)

Aggregations

StatementConstraints (org.apache.rya.indexing.StatementConstraints)19 Statement (org.openrdf.model.Statement)19 Test (org.junit.Test)18 URI (org.openrdf.model.URI)17 ValueFactory (org.openrdf.model.ValueFactory)17 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)17 Value (org.openrdf.model.Value)15 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)14 LinearRing (com.vividsolutions.jts.geom.LinearRing)12 Polygon (com.vividsolutions.jts.geom.Polygon)12 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)12 Resource (org.openrdf.model.Resource)12 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)12 RyaStatement (org.apache.rya.api.domain.RyaStatement)5 RyaURI (org.apache.rya.api.domain.RyaURI)4 MongoGeoIndexer (org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer)4 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)3 HashSet (java.util.HashSet)2 RyaType (org.apache.rya.api.domain.RyaType)2 StatementImpl (org.openrdf.model.impl.StatementImpl)2