use of org.openrdf.model.URI 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.URI 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.URI in project incubator-rya by apache.
the class AccumuloConstantPcjIT method testEvaluateThreeIndexVarInstantiate.
@Test
public void testEvaluateThreeIndexVarInstantiate() throws PcjException, RepositoryException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, MalformedQueryException, SailException, QueryEvaluationException, TupleQueryResultHandlerException {
final URI superclass = new URIImpl("uri:superclass");
final URI superclass2 = new URIImpl("uri:superclass2");
final URI sub = new URIImpl("uri:entity");
subclass = new URIImpl("uri:class");
obj = new URIImpl("uri:obj");
talksTo = new URIImpl("uri:talksTo");
final URI howlsAt = new URIImpl("uri:howlsAt");
final URI subType = new URIImpl("uri:subType");
conn.add(subclass, RDF.TYPE, superclass);
conn.add(subclass2, RDF.TYPE, superclass2);
conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
conn.add(sub, howlsAt, superclass);
conn.add(superclass, subType, obj);
conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
final String indexSparqlString = //
"" + //
"SELECT ?dog ?pig ?duck " + //
"{" + //
" ?pig a ?dog . " + //
" ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?o ?f ?e ?c ?l " + //
"{" + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?c a ?f . " + //
"}";
final String indexSparqlString3 = //
"" + //
"SELECT ?wolf ?sheep ?chicken " + //
"{" + //
" ?wolf <uri:howlsAt> ?sheep . " + //
" ?sheep <uri:subType> ?chicken. " + //
"}";
final String queryString = //
"" + //
"SELECT ?c ?l ?f ?o " + //
"{" + //
" <uri:entity> a ?c . " + //
" <uri:entity> <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" <uri:entity> <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?c a ?f . " + //
" <uri:entity> <uri:howlsAt> ?f. " + //
" ?f <uri:subType> <uri:obj>. " + //
"}";
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1, indexSparqlString, new String[] { "dog", "pig", "duck" }, Optional.<PcjVarOrderFactory>absent());
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 2, indexSparqlString2, new String[] { "o", "f", "e", "c", "l" }, Optional.<PcjVarOrderFactory>absent());
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 3, indexSparqlString3, new String[] { "wolf", "sheep", "chicken" }, Optional.<PcjVarOrderFactory>absent());
final CountingResultHandler crh1 = new CountingResultHandler();
final CountingResultHandler crh2 = new CountingResultHandler();
conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh1);
PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, prefix);
pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh2);
Assert.assertEquals(crh1.getCount(), crh2.getCount());
}
use of org.openrdf.model.URI in project incubator-rya by apache.
the class PrecompJoinOptimizerIT method testEvaluateSingeFilterWithLeftJoin.
@Test
public void testEvaluateSingeFilterWithLeftJoin() throws TupleQueryResultHandlerException, QueryEvaluationException, MalformedQueryException, RepositoryException, AccumuloException, AccumuloSecurityException, TableExistsException, RyaDAOException, SailException, TableNotFoundException, PcjException, InferenceEngineException, NumberFormatException, UnknownHostException {
final String indexSparqlString1 = //
"" + //
"SELECT ?e ?l ?c " + //
"{" + //
" Filter(?l = \"label3\") " + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final URI sub3 = new URIImpl("uri:entity3");
final URI subclass3 = new URIImpl("uri:class3");
conn.add(sub3, RDF.TYPE, subclass3);
conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablePrefix + "INDEX_1", indexSparqlString1, new String[] { "e", "l", "c" }, Optional.<PcjVarOrderFactory>absent());
final String queryString = //
"" + //
"SELECT ?e ?c ?o ?m ?l" + //
"{" + //
" Filter(?l = \"label3\") " + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" OPTIONAL { ?e <uri:talksTo> ?o . ?e <http://www.w3.org/2000/01/rdf-schema#label> ?m }" + //
"}";
final CountingResultHandler crh = new CountingResultHandler();
PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, tablePrefix);
PcjIntegrationTestingUtil.closeAndShutdown(conn, repo);
repo = PcjIntegrationTestingUtil.getAccumuloPcjRepo(tablePrefix, "instance");
conn = repo.getConnection();
conn.add(sub, talksTo, obj);
conn.add(sub, RDFS.LABEL, new LiteralImpl("label"));
pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
Assert.assertEquals(1, crh.getCount());
}
use of org.openrdf.model.URI 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();
}
Aggregations