use of org.semanticweb.owlapi.io.WriterDocumentTarget in project stanbol by apache.
the class TestOWLAPIInputSources method testAutoIRIMapper.
@Test
public void testAutoIRIMapper() throws Exception {
URL url = getClass().getResource("/ontologies");
assertNotNull(url);
File file = new File(url.toURI());
assertTrue(file.exists());
assertTrue(file.isDirectory());
OWLOntologyIRIMapper mapper = new AutoIRIMapper(file, true);
IRI dummyiri = IRI.create("http://stanbol.apache.org/ontologies/peanuts/dummycharacters.owl");
// Cleanup may be required if previous tests have failed.
if (mapper.getDocumentIRI(dummyiri) != null) {
new File(mapper.getDocumentIRI(dummyiri).toURI()).delete();
((AutoIRIMapper) mapper).update();
}
assertFalse(dummyiri.equals(mapper.getDocumentIRI(dummyiri)));
// Create a new ontology in the test resources.
OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(null);
OWLOntology o = mgr.createOntology(dummyiri);
File f = new File(URI.create(url.toString() + "/dummycharacters.owl"));
mgr.saveOntology(o, new WriterDocumentTarget(new FileWriter(f)));
assertTrue(f.exists());
((AutoIRIMapper) mapper).update();
// The old mapper should be able to locate the new ontology.
assertFalse(dummyiri.equals(mapper.getDocumentIRI(dummyiri)));
// A new mapper too
OWLOntologyIRIMapper mapper2 = new AutoIRIMapper(new File(url.toURI()), true);
assertFalse(dummyiri.equals(mapper2.getDocumentIRI(dummyiri)));
// cleanup
f.delete();
}
Aggregations