Search in sources :

Example 1 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.

the class AccumuloTemporalIndexerTest method testQueryWithMultiplePredicates.

/**
 * Test instant after a given instant WITH two different predicates as constraints.
 */
@Test
public void testQueryWithMultiplePredicates() throws IOException, QueryEvaluationException {
    // 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.
    int searchForSeconds = 4;
    int expectedResultCount = 9;
    for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) {
        // <== logic here
        tIndexer.storeStatement(convertStatement(seriesSpo[s]));
    }
    ValueFactory vf = new ValueFactoryImpl();
    // this one to ignore.
    URI pred3_CIRCA_ = vf.createURI(URI_PROPERTY_CIRCA);
    URI pred2_eventTime = vf.createURI(URI_PROPERTY_EVENT_TIME);
    URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
    // add the predicate = EventTime ; Store in an array for verification.
    Statement[] SeriesTs_EventTime = new Statement[expectedResultCount + 1];
    for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) {
        // <== logic here
        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
        Statement statement = new StatementImpl(vf.createURI("foo:CircaEventSubj0" + s), pred3_CIRCA_, vf.createLiteral(seriesTs[s].getAsReadable()));
        tIndexer.storeStatement(convertStatement(statement));
    }
    tIndexer.flush();
    CloseableIteration<Statement, QueryEvaluationException> iter;
    StatementConstraints constraints = new StatementConstraints();
    constraints.setPredicates(new HashSet<URI>(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()) {
        Statement s = iter.next();
        // System.out.println("testQueryWithMultiplePredicates result="+s);
        // <== logic here
        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);
        }
    }
    Assert.assertEquals("Should find count of atTime    rows.", expectedResultCount, count_AtTime);
    Assert.assertEquals("Should find count of eventTime rows.", expectedResultCount, count_EventTime);
}
Also used : StatementConstraints(org.apache.rya.indexing.StatementConstraints) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RyaStatement(org.apache.rya.api.domain.RyaStatement) 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)

Example 2 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.

the class AccumuloTemporalIndexerTest method testStoreStatementWithInterestingLiterals.

@Test
public void testStoreStatementWithInterestingLiterals() throws Exception {
    ValueFactory vf = new ValueFactoryImpl();
    URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
    tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), pred1_atTime, vf.createLiteral("A number of organizations located, gathered, or classed together. [Derived from Concise Oxford English Dictionary, 11th Edition, 2008]"))));
    int rowsStoredActual = printTables("junit testing: Temporal entities stored in testStoreStatement", null, null);
    // 4 index entries per statement
    Assert.assertEquals("Number of rows stored.", 0, rowsStoredActual);
}
Also used : 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)

Example 3 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.

the class CbSailTest method testInsertData.

public void testInsertData() throws Exception {
    URI cpu = vf.createURI(litdupsNS, "cpu");
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
    URI uri1 = vf.createURI(litdupsNS, "uri1");
    URI uri2 = vf.createURI(litdupsNS, "uri2");
    List<Statement> insert = new ArrayList<Statement>();
    insert.add(new StatementImpl(cpu, loadPerc, uri1));
    insert.add(new StatementImpl(cpu, loadPerc, uri2));
    resultEndpoint.expectedBodiesReceived(true);
    template.sendBody(insert);
    assertMockEndpointsSatisfied();
    resultEndpoint.expectedMessageCount(2);
    String query = "select * where {" + "<" + cpu.toString() + "> ?p ?o1." + "}";
    template.sendBodyAndHeader(null, CbSailComponent.SPARQL_QUERY_PROP, query);
    assertMockEndpointsSatisfied();
}
Also used : Statement(org.openrdf.model.Statement) StatementImpl(org.openrdf.model.impl.StatementImpl) ArrayList(java.util.ArrayList) URI(org.openrdf.model.URI)

Example 4 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.

the class TemporalFilterIT method statement.

private static Statement statement(final ZonedDateTime time) {
    final Resource subject = vf.createURI("urn:time");
    final URI predicate = vf.createURI("http://www.w3.org/2006/time/atTime");
    final Value object = vf.createLiteral(time.toString());
    return new StatementImpl(subject, predicate, object);
}
Also used : StatementImpl(org.openrdf.model.impl.StatementImpl) Resource(org.openrdf.model.Resource) Value(org.openrdf.model.Value) URI(org.openrdf.model.URI)

Example 5 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.

the class PcjDocumentsWithMockTest method populatePcj.

@Test
public void populatePcj() throws Exception {
    final RdfCloudTripleStore ryaStore = new RdfCloudTripleStore();
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    dao.setConf(new StatefulMongoDBRdfConfiguration(conf, getMongoClient()));
    dao.init();
    ryaStore.setRyaDAO(dao);
    ryaStore.initialize();
    final SailRepositoryConnection ryaConn = new RyaSailRepository(ryaStore).getConnection();
    try {
        // Load some Triples into Rya.
        final Set<Statement> triples = new HashSet<>();
        triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://hasAge"), new NumericLiteralImpl(14, XMLSchema.INTEGER)));
        triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
        triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://hasAge"), new NumericLiteralImpl(16, XMLSchema.INTEGER)));
        triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
        triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://hasAge"), new NumericLiteralImpl(12, XMLSchema.INTEGER)));
        triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
        triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://hasAge"), new NumericLiteralImpl(43, XMLSchema.INTEGER)));
        triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
        for (final Statement triple : triples) {
            ryaConn.add(triple);
        }
        // Create a PCJ table that will include those triples in its results.
        final String sparql = "SELECT ?name ?age " + "{" + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
        final String pcjTableName = new PcjTableNameFactory().makeTableName(conf.getRyaInstanceName(), "testPcj");
        final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
        pcjs.createAndPopulatePcj(ryaConn, pcjTableName, sparql);
        // Make sure the cardinality was updated.
        final PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
        assertEquals(4, metadata.getCardinality());
    } finally {
        ryaConn.close();
        ryaStore.shutDown();
    }
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) Statement(org.openrdf.model.Statement) RyaSailRepository(org.apache.rya.rdftriplestore.RyaSailRepository) URIImpl(org.openrdf.model.impl.URIImpl) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

StatementImpl (org.openrdf.model.impl.StatementImpl)66 Statement (org.openrdf.model.Statement)40 Test (org.junit.Test)34 URI (org.openrdf.model.URI)32 ValueFactory (org.openrdf.model.ValueFactory)27 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)26 Resource (org.openrdf.model.Resource)19 Value (org.openrdf.model.Value)19 URIImpl (org.openrdf.model.impl.URIImpl)19 HashSet (java.util.HashSet)16 LiteralImpl (org.openrdf.model.impl.LiteralImpl)16 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)15 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)14 BindingSet (org.openrdf.query.BindingSet)14 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)14 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)10 PcjTableNameFactory (org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory)10 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)10 TupleQuery (org.openrdf.query.TupleQuery)7 RepositoryConnection (org.openrdf.repository.RepositoryConnection)7