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);
}
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();
}
}
Aggregations