public void testRealization(String inputOnt) throws IOException {
File testFile = new File( TEST_FILE );
OWLOntology ontology = OntologyUtils.loadOntology( inputOnt );
try {
PelletReasoner unified = PelletReasonerFactory.getInstance().createReasoner( ontology );
ModuleExtractor moduleExtractor = createModuleExtractor();
IncrementalClassifier modular = new IncrementalClassifier( unified, moduleExtractor );
modular.classify();
// first we only persist classified-but-not-realized classifier
assertFalse( modular.isRealized() );
FileOutputStream fos = new FileOutputStream( testFile );
IncrementalClassifierPersistence.save( modular, fos );
fos.close();
FileInputStream fis = new FileInputStream( testFile );
IncrementalClassifier modular2 = IncrementalClassifierPersistence.load( fis );
fis.close();
assertTrue( testFile.delete() );
// the classifier read from file should NOT be realized at this point
assertFalse( modular.isRealized() );
assertInstancesEquals( unified, modular2 );
assertTypesEquals( unified, modular2 );
// the previous tests should have triggered realization
assertTrue( modular2.isRealized() );
// save the classifier again and read it back
fos = new FileOutputStream( testFile );
IncrementalClassifierPersistence.save( modular2, fos );
fos.close();
fis = new FileInputStream( testFile );
IncrementalClassifier modular3 = IncrementalClassifierPersistence.load( fis );
fis.close();
assertTrue( testFile.delete() );
// the classifier read from file should be realized at this point
assertTrue( modular3.isRealized() );
assertInstancesEquals( unified, modular3 );
assertTypesEquals( unified, modular3 );
unified.dispose();
modular.dispose();
modular2.dispose();
modular3.dispose();
}
finally {