Search in sources :

Example 1 with MissingImportListener

use of org.semanticweb.owlapi.model.MissingImportListener 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;
}
Also used : MissingImportListener(org.semanticweb.owlapi.model.MissingImportListener) OWLOntologyLoaderListener(org.semanticweb.owlapi.model.OWLOntologyLoaderListener) MissingImportEvent(org.semanticweb.owlapi.model.MissingImportEvent) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager)

Example 2 with MissingImportListener

use of org.semanticweb.owlapi.model.MissingImportListener 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;
}
Also used : MissingImportEvent(org.semanticweb.owlapi.model.MissingImportEvent) UnknownOWLOntologyException(org.semanticweb.owlapi.model.UnknownOWLOntologyException) URI(java.net.URI) OWLOntologyAlreadyExistsException(org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException) MissingImportListener(org.semanticweb.owlapi.model.MissingImportListener) OWLOntologyLoaderListener(org.semanticweb.owlapi.model.OWLOntologyLoaderListener) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) File(java.io.File) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 3 with MissingImportListener

use of org.semanticweb.owlapi.model.MissingImportListener 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;
}
Also used : MissingImportListener(org.semanticweb.owlapi.model.MissingImportListener) OWLOntologyLoaderListener(org.semanticweb.owlapi.model.OWLOntologyLoaderListener) MissingImportEvent(org.semanticweb.owlapi.model.MissingImportEvent) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager)

Example 4 with MissingImportListener

use of org.semanticweb.owlapi.model.MissingImportListener 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;
}
Also used : MissingImportListener(org.semanticweb.owlapi.model.MissingImportListener) OWLOntologyLoaderListener(org.semanticweb.owlapi.model.OWLOntologyLoaderListener) MissingImportEvent(org.semanticweb.owlapi.model.MissingImportEvent) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager)

Example 5 with MissingImportListener

use of org.semanticweb.owlapi.model.MissingImportListener in project stanbol by apache.

the class AbstractOWLApiReasoningService method createOWLOntologyManager.

/**
     * An OWLOntologyManager to be used to place a target ontology. We don't want to use the manager bound to
     * the input ontologies for that, we don't want to interfere with it.
     * 
     * Other {@see OWLApiReasoningService}s may want to change this.
     * 
     * @return
     */
protected OWLOntologyManager createOWLOntologyManager() {
    log.info("createOWLOntologyManager()");
    // We want a single instance here
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    log.info("manager: {}", manager);
    // 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;
}
Also used : MissingImportListener(org.semanticweb.owlapi.model.MissingImportListener) OWLOntologyLoaderListener(org.semanticweb.owlapi.model.OWLOntologyLoaderListener) MissingImportEvent(org.semanticweb.owlapi.model.MissingImportEvent) LoadingFinishedEvent(org.semanticweb.owlapi.model.OWLOntologyLoaderListener.LoadingFinishedEvent) LoadingStartedEvent(org.semanticweb.owlapi.model.OWLOntologyLoaderListener.LoadingStartedEvent) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager)

Aggregations

MissingImportEvent (org.semanticweb.owlapi.model.MissingImportEvent)6 MissingImportListener (org.semanticweb.owlapi.model.MissingImportListener)6 OWLOntologyLoaderListener (org.semanticweb.owlapi.model.OWLOntologyLoaderListener)5 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)4 File (java.io.File)2 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)2 OWLOntologyAlreadyExistsException (org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException)2 URI (java.net.URI)1 IRI (org.semanticweb.owlapi.model.IRI)1 LoadingFinishedEvent (org.semanticweb.owlapi.model.OWLOntologyLoaderListener.LoadingFinishedEvent)1 LoadingStartedEvent (org.semanticweb.owlapi.model.OWLOntologyLoaderListener.LoadingStartedEvent)1 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)1 UnknownOWLOntologyException (org.semanticweb.owlapi.model.UnknownOWLOntologyException)1