use of org.semanticweb.owlapi.model.OWLOntologyLoaderListener in project stanbol by apache.
the class ODPRegistryCacheManager method retrieveRemoteResource.
/**
* Gets the remote ontology and saves it locally
*
* @param uri
* @return
* @throws OWLOntologyCreationException
* @throws UnknownOWLOntologyException
* @throws OWLOntologyStorageException
*/
private static synchronized OWLOntology retrieveRemoteResource(URI uri) throws OWLOntologyCreationException, UnknownOWLOntologyException, OWLOntologyStorageException {
manager.setSilentMissingImportsHandling(true);
manager.addMissingImportListener(new MissingImportListener() {
public void importMissing(MissingImportEvent arg0) {
if (!getUnresolvedURIs().contains(arg0.getImportedOntologyURI()))
getUnresolvedURIs().add(arg0.getImportedOntologyURI().toURI());
}
});
manager.addOntologyLoaderListener(new OWLOntologyLoaderListener() {
@Override
public void startedLoadingOntology(LoadingStartedEvent event) {
// Nothing to do
}
@Override
public void finishedLoadingOntology(LoadingFinishedEvent event) {
URI onturi = event.getDocumentIRI().toURI();
if (event.getException() != null) {
getUnresolvedURIs().add(onturi);
LoggerFactory.getLogger(ODPRegistryCacheManager.class).warn("Failed to resolve ontology at " + onturi + " . Skipping.", event.getException());
return;
}
try {
if (!uris.containsKey(onturi)) {
cacheOntology(onturi, newFile(), manager.getOntology(event.getOntologyID()));
}
} catch (UnknownOWLOntologyException e) {
LoggerFactory.getLogger(ODPRegistryCacheManager.class).warn("Failed to cache ontology at " + onturi + " . Skipping.", e);
getUnresolvedURIs().add(onturi);
} catch (OWLOntologyStorageException e) {
LoggerFactory.getLogger(ODPRegistryCacheManager.class).warn("Failed to cache ontology at " + onturi + " . Skipping.", e);
getUnresolvedURIs().add(onturi);
}
}
});
OWLOntology ont;
try {
ont = manager.loadOntologyFromOntologyDocument(IRI.create(uri));
} catch (OWLOntologyAlreadyExistsException e) {
ont = manager.getOntology(e.getOntologyID().getOntologyIRI());
}
File file = newFile();
cacheOntology(uri, file, ont);
return ont;
}
use of org.semanticweb.owlapi.model.OWLOntologyLoaderListener in project stanbol by apache.
the class OntologyManagerInputProvider method createOWLOntologyManager.
@SuppressWarnings("deprecation")
private OWLOntologyManager createOWLOntologyManager() {
// We isolate here the creation of the temporary manager
// TODO How to behave when resolving owl:imports?
// We should set the manager to use a service to lookup for ontologies,
// instead of trying on the web directly
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// FIXME Which is the other way of doing this?
// Maybe -> OWLOntologyManagerProperties();
manager.setSilentMissingImportsHandling(true);
// Listening for missing imports
manager.addMissingImportListener(new MissingImportListener() {
@Override
public void importMissing(MissingImportEvent arg0) {
log.warn("Missing import {} ", arg0.getImportedOntologyURI());
}
});
manager.addOntologyLoaderListener(new OWLOntologyLoaderListener() {
@Override
public void finishedLoadingOntology(LoadingFinishedEvent arg0) {
log.info("Finished loading {} (imported: {})", arg0.getOntologyID(), arg0.isImported());
}
@Override
public void startedLoadingOntology(LoadingStartedEvent arg0) {
log.info("Started loading {} (imported: {}) ...", arg0.getOntologyID(), arg0.isImported());
log.info(" ... from {}", arg0.getDocumentIRI().toString());
}
});
return manager;
}
use of org.semanticweb.owlapi.model.OWLOntologyLoaderListener in project stanbol by apache.
the class TestOntologyCollectors method spacePreservesImports.
@Test
public void spacePreservesImports() throws Exception {
InputStream content = getClass().getResourceAsStream("/ontologies/characters_all.owl");
URL url = getClass().getResource("/ontologies/characters_all.owl");
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
mgr.addOntologyLoaderListener(new OWLOntologyLoaderListener() {
@Override
public void startedLoadingOntology(LoadingStartedEvent arg0) {
}
@Override
public void finishedLoadingOntology(LoadingFinishedEvent arg0) {
log.info((arg0.isSuccessful() ? "Loaded" : "Failed") + (arg0.isImported() ? " imported " : " ") + "ontology " + arg0.getDocumentIRI());
}
});
mgr.addIRIMapper(new PhonyIRIMapper(null));
File f = new File(url.toURI());
OntologyInputSource<OWLOntology> src = new ParentPathInputSource(f, mgr);
// OntologyInputSource<OWLOntology> src = new RootOntologyIRISource(IRI.create(f), mgr);
// OntologyInputSource<OWLOntology> src = new OntologyContentInputSource(content,mgr);
OWLOntology original = src.getRootOntology();
Assert.assertNotNull(original);
OntologySpace spc = new CustomSpaceImpl("Test", scopeNs, ontologyProvider);
spc.addOntology(src);
}
use of org.semanticweb.owlapi.model.OWLOntologyLoaderListener in project stanbol by apache.
the class ByteArrayInputProvider method createOWLOntologyManager.
@SuppressWarnings("deprecation")
private OWLOntologyManager createOWLOntologyManager() {
// We isolate here the creation of the temporary manager
// TODO How to behave when resolving owl:imports?
// We should set the manager to use a service to lookup for ontologies,
// instead of trying on the web
// directly/only
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// FIXME Which is the other way of doing this?
// Maybe -> OWLOntologyManagerProperties();
manager.setSilentMissingImportsHandling(true);
// Listening for missing imports
manager.addMissingImportListener(new MissingImportListener() {
@Override
public void importMissing(MissingImportEvent arg0) {
log.warn("Missing import {} ", arg0.getImportedOntologyURI());
}
});
manager.addOntologyLoaderListener(new OWLOntologyLoaderListener() {
@Override
public void finishedLoadingOntology(LoadingFinishedEvent arg0) {
log.info("Finished loading {} (imported: {})", arg0.getOntologyID(), arg0.isImported());
}
@Override
public void startedLoadingOntology(LoadingStartedEvent arg0) {
log.info("Started loading {} (imported: {}) ...", arg0.getOntologyID(), arg0.isImported());
log.info(" ... from {}", arg0.getDocumentIRI().toString());
}
});
return manager;
}
use of org.semanticweb.owlapi.model.OWLOntologyLoaderListener in project stanbol by apache.
the class UrlInputProvider method createOWLOntologyManager.
@SuppressWarnings("deprecation")
private OWLOntologyManager createOWLOntologyManager() {
// We isolate here the creation of the temporary manager
// TODO How to behave when resolving owl:imports?
// We should set the manager to use a service to lookup for ontologies,
// instead of trying on the web
// directly
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// FIXME Which is the other way of doing this?
// Maybe -> OWLOntologyManagerProperties();
manager.setSilentMissingImportsHandling(true);
// Listening for missing imports
manager.addMissingImportListener(new MissingImportListener() {
@Override
public void importMissing(MissingImportEvent arg0) {
log.warn("Missing import {} ", arg0.getImportedOntologyURI());
}
});
manager.addOntologyLoaderListener(new OWLOntologyLoaderListener() {
@Override
public void finishedLoadingOntology(LoadingFinishedEvent arg0) {
log.info("Finished loading {} (imported: {})", arg0.getOntologyID(), arg0.isImported());
}
@Override
public void startedLoadingOntology(LoadingStartedEvent arg0) {
log.info("Started loading {} (imported: {}) ...", arg0.getOntologyID(), arg0.isImported());
log.info(" ... from {}", arg0.getDocumentIRI().toString());
}
});
return manager;
}
Aggregations