// load the statement from the connection so we can add it to the reasoner
List<Statement> statements = Iterations.asList(con.getStatements(null,property,null, false));
Assert.assertEquals(2,statements.size());
// add triples to engine
TransactionData data = new TransactionData();
data.getAddedTriples().addAll(statements);
engine.afterCommit(data);
// wait for reasoning to complete
while(engine.isRunning()) {
log.debug("sleeping for 100ms to let engine finish processing ... ");
Thread.sleep(100);
}
con.begin();
// after the engine completes, we check whether
// 1) the expected inferred triple exists (must be (ex:a ex:transitive ex:c) )
// 2) the inferred triple is properly justified (based on rule2 and on the triple contained in the transaction data)
List<Statement> inferred = Iterations.asList(con.getStatements(a,property,c, true));
Assert.assertEquals("number of inferred triples differs from expected result",1,inferred.size());
KiWiTriple triple = (KiWiTriple)inferred.get(0);
List<Justification> justifications = Iterations.asList(rcon.listJustificationsForTriple(triple));
Assert.assertEquals("number of justifications for triple differs from expected result",1,justifications.size());
Justification j = justifications.get(0);
Assert.assertEquals("number of supporting triples differs from expected result",2,j.getSupportingTriples().size());
Assert.assertEquals("number of supporting rules differs from expected result",1,j.getSupportingRules().size());
Assert.assertThat("supporting triple does not match expectation", j.getSupportingTriples(), hasItem((KiWiTriple)statements.get(0)));
Assert.assertThat("supporting triple does not match expectation", j.getSupportingTriples(), hasItem((KiWiTriple)statements.get(1)));
con.commit();
// add another triple and check if the incremental reasoning works
con.add(c,property,d);
con.commit();
// load the statement from the connection so we can add it to the reasoner
List<Statement> statements2 = Iterations.asList(con.getStatements(c,property,d, false));
Assert.assertEquals(1, statements2.size());
// add triples to engine
TransactionData data2 = new TransactionData();
data2.getAddedTriples().addAll(statements2);
engine.afterCommit(data2);
// wait for reasoning to complete
while(engine.isRunning()) {
log.debug("sleeping for 100ms to let engine finish processing ... ");
Thread.sleep(100);
}
con.begin();
// after the engine completes, we check whether the expected inferred triples exist
// (must be (ex:a ex:transitive ex:d) and (ex:b ex:transitive ex:d) )
List<Statement> inferred2 = Iterations.asList(con.getStatements(a,property,d, true));
Assert.assertEquals("number of inferred triples differs from expected result", 1, inferred2.size());
List<Statement> inferred3 = Iterations.asList(con.getStatements(b,property,d, true));
Assert.assertEquals("number of inferred triples differs from expected result", 1, inferred3.size());
// now remove again the base triple and inform the reasoner about it, as a consequence, the inferred
// triple should also be removed
con.remove(c, property, d);
con.commit();
TransactionData data3 = new TransactionData();
data3.getRemovedTriples().add(statements2.get(0));
engine.afterCommit(data3);
// wait for reasoning to complete
while(engine.isRunning()) {
log.debug("sleeping for 100ms to let engine finish processing ... ");