use of org.semanticweb.owlapi.util.AutoIRIMapper in project stanbol by apache.
the class TestOntologyRegistry method setupSources.
/**
* Resets the virgin ontology manager for each test.
*
* @throws Exception
*/
@Before
public void setupSources() throws Exception {
virginOntologyManager = OWLManager.createOWLOntologyManager();
// Add mappings for any ontologies found in ontologies/registry
URL url = getClass().getResource("/ontologies/registry");
assertNotNull(url);
virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
// Population is lazy; no need to add other mappers.
}
use of org.semanticweb.owlapi.util.AutoIRIMapper in project stanbol by apache.
the class TestOntologyLibrary method setup.
/**
* Resets the {@link OWLOntologyManager} used for tests, since caching phenomena across tests could bias
* the results.
*
* @throws Exception
* if any error occurs;
*/
@Before
public void setup() throws Exception {
virginOntologyManager = OWLManager.createOWLOntologyManager();
URL url = getClass().getResource("/ontologies");
virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
url = getClass().getResource("/ontologies/registry");
virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
// *Not* adding mappers to empty resource directories.
// It seems the Maven surefire plugin won't copy them.
// url = getClass().getResource("/ontologies/odp");
// virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
}
use of org.semanticweb.owlapi.util.AutoIRIMapper 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