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);
}
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);
}
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();
}
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);
}
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();
}
}
Aggregations