Search in sources :

Example 6 with ClerezzaOntologyProvider

use of org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider in project stanbol by apache.

the class TestRegistryManager method cleanup.

@After
public void cleanup() throws Exception {
    MockOsgiContext.reset();
    provider = new ClerezzaOntologyProvider(tcManager, offline, parser);
}
Also used : ClerezzaOntologyProvider(org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider) After(org.junit.After)

Example 7 with ClerezzaOntologyProvider

use of org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider in project stanbol by apache.

the class RegistryManagerImpl method activate.

protected void activate(Dictionary<String, Object> configuration) {
    // Parse configuration.
    try {
        lazyLoading = (Boolean) (configuration.get(RegistryManager.LAZY_LOADING));
    } catch (Exception ex) {
        lazyLoading = _LAZY_LOADING_DEFAULT;
    }
    try {
        retainIncomplete = (Boolean) (configuration.get(RegistryManager.RETAIN_INCOMPLETE));
    } catch (Exception ex) {
        retainIncomplete = _RETAIN_INCOMPLETE_DEFAULT;
    }
    Object obj = configuration.get(RegistryManager.REGISTRY_LOCATIONS);
    if (obj instanceof String[])
        locations = (String[]) obj;
    else if (obj instanceof String)
        locations = new String[] { (String) obj };
    if (locations == null)
        locations = new String[] { "stanbol_network.owl" };
    Object cachingPolicy = configuration.get(RegistryManager.CACHING_POLICY);
    if (cachingPolicy == null) {
        this.cachingPolicyString = _CACHING_POLICY_DEFAULT.name();
    } else {
        this.cachingPolicyString = cachingPolicy.toString();
    }
    final IRI[] offlineResources;
    if (this.offline != null) {
        List<IRI> paths = offline.getOntologySourceLocations();
        if (paths != null)
            offlineResources = paths.toArray(new IRI[0]);
        else
            // There are no offline paths.
            offlineResources = new IRI[0];
    } else
        // There's no offline configuration at all.
        offlineResources = new IRI[0];
    // Used only for creating the registry model, do not use for caching.
    OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(offlineResources);
    OWLOntologyLoaderConfiguration conf = new OWLOntologyLoaderConfiguration();
    // If we are retaining incomplete registries, do not throw exceptions if imports fail.
    conf.setSilentMissingImportsHandling(retainIncomplete);
    // Load registries
    Set<OWLOntology> regOnts = new HashSet<OWLOntology>();
    for (String loc : locations) {
        try {
            IRI iri = IRI.create(loc);
            OWLOntologyDocumentSource src = null;
            OWLOntology o = null;
            if (iri.isAbsolute())
                src = new IRIDocumentSource(iri);
            else {
                // Relative IRI : use data file provider
                log.debug("Found relative IRI {} . Will try to retrieve from data file providers.", iri);
                Map<String, String> info = new HashMap<String, String>();
                if (dataFileProvider != null && dataFileProvider.isAvailable(null, loc, info))
                    src = new StreamDocumentSource(dataFileProvider.getInputStream(null, loc, info));
            }
            if (src != null)
                o = mgr.loadOntologyFromOntologyDocument(src, conf);
            if (o != null)
                regOnts.add(o);
            else
                log.warn("Failed to obtain OWL ontology from resource {}", loc);
        } catch (OWLOntologyAlreadyExistsException e) {
            log.info("Skipping cached ontology {}.", e.getOntologyID());
            continue;
        } catch (OWLOntologyCreationException e) {
            log.warn("Failed to load ontology " + loc + " - Skipping...", e);
            continue;
        } catch (Exception e) {
            log.warn("Invalid registry configuration " + loc + " - Skipping...", e);
            continue;
        }
    }
    // Create and set the cache.
    if (cachingPolicyString.equals(CachingPolicy.CENTRALISED.name())) {
        // this.cache = OWLOntologyManagerFactory.createOWLOntologyManager(offlineResources);
        if (cache == null) {
            log.warn("Caching policy is set as Centralised, but no ontology provider is supplied. Will use new in-memory tcProvider.");
            cache = new ClerezzaOntologyProvider(TcManager.getInstance(), offline, Parser.getInstance());
        }
    // else sta bene cosi'
    } else if (cachingPolicyString.equals(CachingPolicy.DISTRIBUTED.name())) {
        this.cache = null;
    }
    riFactory = new RegistryItemFactoryImpl(cache);
    // Build the model.
    createModel(regOnts);
    // Set the cache on libraries.
    Set<RegistryItem> visited = new HashSet<RegistryItem>();
    for (Registry reg : getRegistries()) for (RegistryItem child : reg.getChildren()) if (!visited.contains(child)) {
        if (child instanceof Library) {
            if (this.cache != null)
                ((Library) child).setCache(this.cache);
            else
                ((Library) child).setCache(new ClerezzaOntologyProvider(TcManager.getInstance(), offline, Parser.getInstance()));
        }
        visited.add(child);
    }
    if (isLazyLoading()) {
    // Nothing to do about it at the moment.
    } else {
        loadEager();
    }
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) HashMap(java.util.HashMap) OWLOntologyLoaderConfiguration(org.semanticweb.owlapi.model.OWLOntologyLoaderConfiguration) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) IRIDocumentSource(org.semanticweb.owlapi.io.IRIDocumentSource) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyAlreadyExistsException(org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OWLOntologyAlreadyExistsException(org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException) StreamDocumentSource(org.semanticweb.owlapi.io.StreamDocumentSource) ClerezzaOntologyProvider(org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedObject(org.semanticweb.owlapi.model.OWLNamedObject) OWLObject(org.semanticweb.owlapi.model.OWLObject) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) OWLOntologyDocumentSource(org.semanticweb.owlapi.io.OWLOntologyDocumentSource) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) HashSet(java.util.HashSet)

Aggregations

ClerezzaOntologyProvider (org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider)7 Hashtable (java.util.Hashtable)4 RegistryManagerImpl (org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl)3 IRI (org.semanticweb.owlapi.model.IRI)3 SimpleTcProvider (org.apache.clerezza.rdf.simple.storage.SimpleTcProvider)2 OfflineConfigurationImpl (org.apache.stanbol.ontologymanager.core.OfflineConfigurationImpl)2 ClerezzaCollectorFactory (org.apache.stanbol.ontologymanager.multiplexer.clerezza.collector.ClerezzaCollectorFactory)2 Library (org.apache.stanbol.ontologymanager.registry.api.model.Library)2 Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)2 RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Graph (org.apache.clerezza.commons.rdf.Graph)1 TcManager (org.apache.clerezza.rdf.core.access.TcManager)1 ScopeRegistryImpl (org.apache.stanbol.ontologymanager.core.scope.ScopeRegistryImpl)1 RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)1