Search in sources :

Example 1 with FileDocumentSource

use of org.semanticweb.owlapi.io.FileDocumentSource in project stanbol by apache.

the class ScopeManagerImpl method activate.

/**
     * Called within both OSGi and non-OSGi environments.
     * 
     * @param configuration
     * @throws IOException
     */
protected void activate(Dictionary<String, Object> configuration) throws IOException {
    long before = System.currentTimeMillis();
    // Assign singleton instance
    me = this;
    // Parse configuration
    if (offline != null)
        ontonetNS = offline.getDefaultOntologyNetworkNamespace();
    scopeRegistryId = (String) configuration.get(ScopeManager.ID_SCOPE_REGISTRY);
    if (scopeRegistryId == null)
        scopeRegistryId = _ID_SCOPE_REGISTRY_DEFAULT;
    configPath = (String) configuration.get(ScopeManager.CONFIG_ONTOLOGY_PATH);
    if (configPath == null)
        configPath = _CONFIG_ONTOLOGY_PATH_DEFAULT;
    // Bind components, starting with the local directories.
    List<String> dirs = new ArrayList<String>();
    try {
        for (IRI iri : offline.getOntologySourceLocations()) dirs.add(iri.toString());
    } catch (NullPointerException ex) {
    // Ok, go empty
    }
    bindResources();
    // String tfile = (String) configuration.get(CONFIG_FILE_PATH);
    // if (tfile != null) this.configPath = tfile;
    // String tns = (String) configuration.get(KRES_NAMESPACE);
    // if (tns != null) this.kresNs = tns;
    // configPath = (String) configuration.get(CONFIG_FILE_PATH);
    // If there is no configuration file, just start with an empty scope set
    Object connectivityPolicy = configuration.get(ScopeManager.CONNECTIVITY_POLICY);
    if (connectivityPolicy == null) {
        this.connectivityPolicyString = _CONNECTIVITY_POLICY_DEFAULT;
    } else {
        this.connectivityPolicyString = connectivityPolicy.toString();
    }
    String configPath = getOntologyNetworkConfigurationPath();
    if (configPath != null && !configPath.trim().isEmpty()) {
        OWLOntology oConf = null;
        OWLOntologyManager tempMgr = OWLOntologyManagerFactory.createOWLOntologyManager(offline.getOntologySourceLocations().toArray(new IRI[0]));
        OWLOntologyDocumentSource oConfSrc = null;
        try {
            log.debug("Try to load the configuration ontology from a local bundle relative path");
            InputStream is = this.getClass().getResourceAsStream(configPath);
            oConfSrc = new StreamDocumentSource(is);
        } catch (Exception e1) {
            try {
                log.debug("Cannot load from a local bundle relative path", e1);
                log.debug("Try to load the configuration ontology resolving the given IRI");
                IRI iri = IRI.create(configPath);
                if (!iri.isAbsolute())
                    throw new Exception("IRI seems to be not absolute! value was: " + iri.toQuotedString());
                oConfSrc = new IRIDocumentSource(iri);
            } catch (Exception e) {
                try {
                    log.debug("Cannot load from the web", e1);
                    log.debug("Try to load the configuration ontology as full local file path");
                    oConfSrc = new FileDocumentSource(new File(configPath));
                } catch (Exception e2) {
                    log.error("Cannot load the configuration ontology from parameter value: " + configPath, e2);
                }
            }
        }
        if (oConfSrc == null) {
            log.warn("No ONM configuration file found at path " + configPath + ". Starting with blank scope set.");
        } else {
            try {
                oConf = tempMgr.loadOntologyFromOntologyDocument(oConfSrc);
            } catch (OWLOntologyCreationException e) {
                log.error("Cannot create the configuration ontology", e);
            }
        }
        // Create and populate the scopes from the config ontology.
        bootstrapOntologyNetwork(oConf);
    } else {
        // No ontology supplied. Access the local graph
        rebuildScopes();
    }
    log.debug(ScopeManager.class + " activated. Time : {} ms.", System.currentTimeMillis() - before);
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IRIDocumentSource(org.semanticweb.owlapi.io.IRIDocumentSource) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) NoSuchScopeException(org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException) MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) DuplicateIDException(org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException) IOException(java.io.IOException) StreamDocumentSource(org.semanticweb.owlapi.io.StreamDocumentSource) ScopeManager(org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeManager) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) FileDocumentSource(org.semanticweb.owlapi.io.FileDocumentSource) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLOntologyDocumentSource(org.semanticweb.owlapi.io.OWLOntologyDocumentSource) File(java.io.File)

Example 2 with FileDocumentSource

use of org.semanticweb.owlapi.io.FileDocumentSource in project stanbol by apache.

the class ODPRegistryCacheManager method getOntologyInputSource.

public static synchronized OWLOntologyDocumentSource getOntologyInputSource(URI uri) throws ODPRegistryCacheException, URIUnresolvableException {
    if (getUnresolvedURIs().contains(uri))
        throw new URIUnresolvableException();
    if (uris.containsKey(uri)) {
        File f = uris.get(uri);
        FileDocumentSource fds = new FileDocumentSource(f);
        return fds;
    } else {
        try {
            retrieveRemoteResource(uri);
            return getOntologyInputSource(uri);
        } catch (UnknownOWLOntologyException e) {
            throw new ODPRegistryCacheException(e);
        } catch (OWLOntologyCreationException e) {
            throw new ODPRegistryCacheException(e);
        } catch (OWLOntologyStorageException e) {
            throw new ODPRegistryCacheException(e);
        }
    }
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) FileDocumentSource(org.semanticweb.owlapi.io.FileDocumentSource) UnknownOWLOntologyException(org.semanticweb.owlapi.model.UnknownOWLOntologyException) File(java.io.File) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Aggregations

File (java.io.File)2 FileDocumentSource (org.semanticweb.owlapi.io.FileDocumentSource)2 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 DuplicateIDException (org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException)1 MissingOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException)1 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)1 NoSuchScopeException (org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException)1 ScopeManager (org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeManager)1 IRIDocumentSource (org.semanticweb.owlapi.io.IRIDocumentSource)1 OWLOntologyDocumentSource (org.semanticweb.owlapi.io.OWLOntologyDocumentSource)1 StreamDocumentSource (org.semanticweb.owlapi.io.StreamDocumentSource)1 IRI (org.semanticweb.owlapi.model.IRI)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)1 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)1 UnknownOWLOntologyException (org.semanticweb.owlapi.model.UnknownOWLOntologyException)1