Search in sources :

Example 6 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer in project incubator-rya by apache.

the class MongoTemporalIndexerIT method testQueryIntervalBefore.

/**
 * Test interval before a given interval, for method:
 * {@link MongoTemporalIndexer#queryIntervalBefore(TemporalInterval, StatementConstraints)}.
 *
 * @throws IOException
 * @throws QueryEvaluationException
 */
@Test
public void testQueryIntervalBefore() throws IOException, QueryEvaluationException {
    try (MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
        tIndexer.setConf(conf);
        tIndexer.init();
        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
        tIndexer.storeStatement(convertStatement(spo_B00_E01));
        tIndexer.storeStatement(convertStatement(spo_B02_E30));
        tIndexer.storeStatement(convertStatement(spo_B02_E31));
        tIndexer.storeStatement(convertStatement(spo_B02_E40));
        tIndexer.storeStatement(convertStatement(spo_B03_E20));
        // instants should be ignored.
        tIndexer.storeStatement(convertStatement(spo_B30_E32));
        // instance at 1 seconds
        tIndexer.storeStatement(convertStatement(seriesSpo[1]));
        tIndexer.storeStatement(convertStatement(seriesSpo[2]));
        tIndexer.storeStatement(convertStatement(seriesSpo[31]));
        CloseableIteration<Statement, QueryEvaluationException> iter;
        iter = tIndexer.queryIntervalBefore(tvB02_E31, EMPTY_CONSTRAINTS);
        // Should be found twice:
        assertTrue("spo_B00_E01 should be found, but actually returned empty results. spo_B00_E01=" + spo_B00_E01, iter.hasNext());
        assertTrue("spo_B00_E01 should be found, but found another.", spo_B00_E01.equals(iter.next()));
        assertFalse("Find no more than one, but actually has more.", iter.hasNext());
    }
}
Also used : 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) Test(org.junit.Test)

Example 7 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer in project incubator-rya by apache.

the class MongoTemporalIndexerIT method testQueryIntervalAfter.

/**
 * interval is after the given interval.  Find interval beginnings after the endings of the given interval.
 * {@link MongoTemporalIndexer#queryIntervalAfter(TemporalInterval, StatementContraints).
 *
 * @throws IOException
 * @throws QueryEvaluationException
 */
@Test
public void testQueryIntervalAfter() throws IOException, QueryEvaluationException {
    try (MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
        tIndexer.setConf(conf);
        tIndexer.init();
        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
        tIndexer.storeStatement(convertStatement(spo_B00_E01));
        // <- after this one.
        tIndexer.storeStatement(convertStatement(spo_B02_E29));
        tIndexer.storeStatement(convertStatement(spo_B02_E30));
        tIndexer.storeStatement(convertStatement(spo_B02_E31));
        tIndexer.storeStatement(convertStatement(spo_B02_E40));
        tIndexer.storeStatement(convertStatement(spo_B03_E20));
        tIndexer.storeStatement(convertStatement(spo_B29_E30));
        tIndexer.storeStatement(convertStatement(spo_B30_E32));
        // instants should be ignored.
        tIndexer.storeStatement(convertStatement(spo_B02));
        // instance at 1 seconds
        tIndexer.storeStatement(convertStatement(seriesSpo[1]));
        tIndexer.storeStatement(convertStatement(seriesSpo[2]));
        tIndexer.storeStatement(convertStatement(seriesSpo[31]));
        CloseableIteration<Statement, QueryEvaluationException> iter;
        iter = tIndexer.queryIntervalAfter(tvB02_E29, EMPTY_CONSTRAINTS);
        // Should be found twice:
        assertTrue("spo_B30_E32 should be found, but actually returned empty results. spo_B30_E32=" + spo_B30_E32, iter.hasNext());
        final Statement s = iter.next();
        assertTrue("spo_B30_E32 should be found, but found another. spo_B30_E32=" + spo_B30_E32 + ", but found=" + s, spo_B30_E32.equals(s));
        assertFalse("Find no more than one, but actually has more.", iter.hasNext());
    }
}
Also used : 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) Test(org.junit.Test)

Example 8 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer in project incubator-rya by apache.

the class MongoTemporalIndexerIT method testQueryInstantHasBeginningInterval.

/**
 * Test instant is the Beginning of the given interval.
 * from the series: Instance {hasBeginning, hasEnd} Interval
 */
@Test
public void testQueryInstantHasBeginningInterval() 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 instants for s seconds after the uniform time.
        // from 2 to 31 seconds
        final TemporalInterval searchInsideInterval = tvB02_E31;
        // <== logic here, and next few lines.
        final int searchSeconds = 2;
        // 2 seconds.
        final int expectedResultCount = 1;
        for (int s = 0; s <= 10; s++) {
            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
        }
        CloseableIteration<Statement, QueryEvaluationException> iter;
        iter = tIndexer.queryInstantHasBeginningInterval(searchInsideInterval, EMPTY_CONSTRAINTS);
        int count = 0;
        while (iter.hasNext()) {
            final Statement s = iter.next();
            // <== logic here
            final Statement nextExpectedStatement = seriesSpo[searchSeconds];
            assertTrue("Should match: " + nextExpectedStatement + " == " + s, nextExpectedStatement.equals(s));
            count++;
        }
        assertEquals("Should find count of rows.", expectedResultCount, count);
    }
}
Also used : 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) TemporalInterval(org.apache.rya.indexing.TemporalInterval) Test(org.junit.Test)

Example 9 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer in project incubator-rya by apache.

the class MongoTemporalIndexerIT method testQueryInstantHasEndInterval.

/**
 * Test instant is the end of the given interval.
 * from the series: Instance {hasBeginning, hasEnd} Interval
 */
@Test
public void testQueryInstantHasEndInterval() 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 instants for s seconds after the uniform time.
        // from 2 to 31 seconds
        final TemporalInterval searchInsideInterval = tvB02_E31;
        // <== logic here, and next few lines.
        final int searchSeconds = 31;
        // 31 seconds.
        final int expectedResultCount = 1;
        for (int s = 0; s <= 40; s++) {
            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
        }
        CloseableIteration<Statement, QueryEvaluationException> iter;
        iter = tIndexer.queryInstantHasEndInterval(searchInsideInterval, EMPTY_CONSTRAINTS);
        int count = 0;
        while (iter.hasNext()) {
            final Statement s = iter.next();
            // <== logic here
            final Statement nextExpectedStatement = seriesSpo[searchSeconds];
            assertTrue("Should match: " + nextExpectedStatement + " == " + s, nextExpectedStatement.equals(s));
            count++;
        }
        assertEquals("Should find count of rows.", expectedResultCount, count);
    }
}
Also used : 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) TemporalInterval(org.apache.rya.indexing.TemporalInterval) Test(org.junit.Test)

Example 10 with MongoTemporalIndexer

use of org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer 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

RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)13 MongoTemporalIndexer (org.apache.rya.indexing.mongodb.temporal.MongoTemporalIndexer)13 Test (org.junit.Test)13 Statement (org.openrdf.model.Statement)13 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)11 TemporalInterval (org.apache.rya.indexing.TemporalInterval)5 URI (org.openrdf.model.URI)3 ValueFactory (org.openrdf.model.ValueFactory)3 StatementImpl (org.openrdf.model.impl.StatementImpl)3 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)3 DB (com.mongodb.DB)1 DBCollection (com.mongodb.DBCollection)1 StatementConstraints (org.apache.rya.indexing.StatementConstraints)1