* functions.
*
*/
@Test
public void testStoreJustifications() throws Exception {
KiWiValueFactory v = (KiWiValueFactory) repository.getValueFactory();
URI ctxb = v.createURI("http://localhost/context/default");
URI ctxi = v.createURI("http://localhost/context/inferred");
URI s1 = v.createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
URI s2 = v.createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
URI s3 = v.createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
URI p1 = v.createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
URI p2 = v.createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
URI o1 = v.createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
URI o2 = v.createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
URI o3 = v.createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
// first, load a sample program (it does not really matter what it actually contains, since we are not really
// running the reasoner)
KWRLProgramParserBase parser = new KWRLProgramParser(v, this.getClass().getResourceAsStream("test-001.kwrl"));
Program p = parser.parseProgram();
p.setName("test-001");
KiWiReasoningConnection connection = rpersistence.getConnection();
try {
// should not throw an exception and the program should have a database ID afterwards
connection.storeProgram(p);
connection.commit();
} finally {
connection.close();
}
// then get a connection to the repository and create a number of triples, some inferred and some base
RepositoryConnection con = repository.getConnection();
try {
con.add(s1,p1,o1);
con.add(s2,p1,o2);
con.add(s3,p1,o3);
con.add(s1,p2,o1,ctxi);
con.add(s2,p2,o2,ctxi);
con.add(s3,p2,o3,ctxi);
con.commit();
} finally {
con.close();
}
connection = rpersistence.getConnection();
try {
// retrieve the persisted triples and put them into two sets to build justifications
List<Statement> baseTriples = asList(connection.listTriples(null,null,null,v.convert(ctxb),false, true));
List<Statement> infTriples = asList(connection.listTriples(null,null,null,v.convert(ctxi),true, true));
Assert.assertEquals("number of base triples was not 3", 3, baseTriples.size());
Assert.assertEquals("number of inferred triples was not 3", 3, infTriples.size());
// we manually update the "inferred" flag for all inferred triples, since this is not possible through the