use of edu.stanford.bmir.protege.web.server.inject.project.RootOntologyDocument in project webprotege by protegeproject.
the class ProjectDocumentStore method loadProjectOntologiesIntoManager.
private OWLOntology loadProjectOntologiesIntoManager(OWLOntologyManager manager) throws OWLOntologyCreationException {
logger.info("{} Loading project", projectId);
long t0 = System.currentTimeMillis();
OWLOntologyLoaderListener loaderListener = new OWLOntologyLoaderListener() {
public void startedLoadingOntology(LoadingStartedEvent event) {
logger.info("{} Ontology loading started: {}", projectId, event.getDocumentIRI());
}
public void finishedLoadingOntology(LoadingFinishedEvent event) {
// Give something else a chance - in case we have LOTS of imports
Thread.yield();
if (event.isSuccessful()) {
logger.info("{} Ontology loading finished: (Loaded: {})", projectId, event.getDocumentIRI(), event.getOntologyID());
MemoryMonitor memoryMonitor = new MemoryMonitor(logger);
memoryMonitor.monitorMemoryUsage();
} else {
logger.info("Ontology loading failed: {} (Reason: )", projectId, event.getException().getMessage());
}
}
};
manager.addOntologyLoaderListener(loaderListener);
final MissingImportListener missingImportListener = (MissingImportListener) missingImportEvent -> logger.info("{} Missing import: {} due to {}", projectId, missingImportEvent.getImportedOntologyURI(), missingImportEvent.getCreationException().getMessage());
manager.addMissingImportListener(missingImportListener);
manager.getIRIMappers().add((OWLOntologyIRIMapper) iri -> {
logger.info("{} Fetching imported ontology from {}.", projectId, iri.toQuotedString());
return iri;
});
// Important - add last
ImportsCacheManager importsCacheManager = importsCacheManagerProvider.get();
OWLOntologyIRIMapper iriMapper = importsCacheManager.getIRIMapper();
manager.getIRIMappers().add(iriMapper);
try {
OWLOntologyLoaderConfiguration config = new OWLOntologyLoaderConfiguration();
config = config.setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT);
config = config.setReportStackTraces(true);
// It is safe to turn of illegal punning fixing as we've already parsed (and saved) the ontology
// using a manager with this turned on.
config = config.setRepairIllegalPunnings(false);
logger.info("{} Loading root ontology imports closure.", projectId);
ProjectInputSource projectInputSource = new ProjectInputSource(rootOntologyDocument);
OWLOntology rootOntology = manager.loadOntologyFromOntologyDocument(projectInputSource, config);
importsCacheManager.cacheImports(rootOntology);
return rootOntology;
} finally {
long t1 = System.currentTimeMillis();
logger.info("{} Ontology loading completed in {} ms.", projectId, (t1 - t0));
MemoryMonitor memoryMonitor = new MemoryMonitor(logger);
memoryMonitor.monitorMemoryUsage();
memoryMonitor.logMemoryUsage();
manager.removeIRIMapper(iriMapper);
manager.removeOntologyLoaderListener(loaderListener);
manager.removeMissingImportListener(missingImportListener);
}
}
Aggregations