use of com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException in project snow-owl by b2ihealthcare.
the class ClassificationJobRequest method executeClassification.
private void executeClassification(final BranchContext context, final String classificationId, final ClassificationTracker tracker) {
final RevisionSearcher revisionSearcher = context.service(RevisionSearcher.class);
TerminologyResource resource = context.service(TerminologyResource.class);
@SuppressWarnings("unchecked") final Set<String> reasonerExcludedModuleIds = Collections3.toImmutableSet((Iterable) resource.getSettings().getOrDefault(REASONER_EXCLUDE_MODULE_IDS, Collections.emptySet()));
final SnomedCoreConfiguration configuration = context.service(SnomedCoreConfiguration.class);
final boolean concreteDomainSupported = configuration.isConcreteDomainSupported();
final ReasonerTaxonomy taxonomy;
try (Locks locks = Locks.on(context).lock(DatastoreLockContextDescriptions.CLASSIFY, parentLockContext)) {
taxonomy = buildTaxonomy(revisionSearcher, reasonerExcludedModuleIds, concreteDomainSupported);
} catch (final LockedException e) {
throw new ReasonerApiException("Couldn't acquire exclusive access to terminology store for classification; %s", e.getMessage(), e);
}
final OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
ontologyManager.getOntologyFactories().add(new DelegateOntologyFactory(taxonomy));
// TODO: custom moduleId in ontology IRI?
final IRI ontologyIRI = IRI.create(DelegateOntology.NAMESPACE_SCTM + Concepts.MODULE_SCT_CORE);
try {
final DelegateOntology ontology = (DelegateOntology) ontologyManager.createOntology(ontologyIRI);
final ReasonerTaxonomyInferrer inferrer = new ReasonerTaxonomyInferrer(reasonerId, ontology, context);
final ReasonerTaxonomy inferredTaxonomy = inferrer.addInferences(taxonomy);
final NormalFormGenerator normalFormGenerator = new NormalFormGenerator(inferredTaxonomy);
tracker.classificationCompleted(classificationId, inferredTaxonomy, normalFormGenerator);
} catch (final OWLOntologyCreationException e) {
throw new ReasonerApiException("Exception caught while creating ontology instance.", e);
} catch (final ReasonerInterruptedException | OWLReasonerRuntimeException e) {
throw new ReasonerApiException("Exception caught while classifying the ontology.", e);
}
}
use of com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException in project snow-owl by b2ihealthcare.
the class SaveJobRequest method execute.
@Override
public Boolean execute(final BranchContext context) {
final IProgressMonitor monitor = context.service(IProgressMonitor.class);
final ClassificationTracker tracker = context.service(ClassificationTracker.class);
final String user = !Strings.isNullOrEmpty(userId) ? userId : context.service(User.class).getUsername();
try (Locks locks = Locks.on(context).user(user).lock(DatastoreLockContextDescriptions.SAVE_CLASSIFICATION_RESULTS, parentLockContext)) {
return persistChanges(context, monitor);
} catch (final LockedException e) {
tracker.classificationFailed(classificationId);
throw new ReasonerApiException("Couldn't acquire exclusive access to terminology store for persisting classification changes; %s", e.getMessage(), e);
} catch (final Exception e) {
LOG.error("Unexpected error while persisting classification changes.", e);
tracker.classificationSaveFailed(classificationId);
throw new ReasonerApiException("Error while persisting classification changes on '%s'.", context.path(), e);
} finally {
monitor.done();
}
}
use of com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException in project snow-owl by b2ihealthcare.
the class ClassificationJobRequest method execute.
@Override
public Boolean execute(final BranchContext context) {
final RemoteJob job = context.service(RemoteJob.class);
final String classificationId = job.getKey();
final Branch branch = context.branch();
final long headTimestamp = branch.headTimestamp();
final ClassificationTracker tracker = context.service(ClassificationTracker.class);
tracker.classificationRunning(classificationId, headTimestamp);
try {
executeClassification(context, classificationId, tracker);
} catch (final ReasonerApiException e) {
tracker.classificationFailed(classificationId);
throw e;
} catch (final Exception e) {
LOGGER.error("Unexpected error encountered while running classification job.", e);
tracker.classificationFailed(classificationId);
throw new ReasonerApiException("Exception caught while running classification.", e);
}
return Boolean.TRUE;
}
use of com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException in project snow-owl by b2ihealthcare.
the class ReasonerTaxonomyInferrer method createReasoner.
private static OWLReasoner createReasoner(final String reasonerId, final OWLOntology owlOntology) {
final IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_ID);
final IExtension[] extensions = extensionPoint.getExtensions();
for (final IExtension extension : extensions) {
final IConfigurationElement[] configurationElements = extension.getConfigurationElements();
final String extensionId = extension.getUniqueIdentifier();
if (reasonerId.equals(extensionId)) {
final Optional<IConfigurationElement> classElement = Arrays.asList(configurationElements).stream().filter(e -> CLASS_ELEMENT.equals(e.getName())).findFirst();
if (!classElement.isPresent()) {
throw new ReasonerApiException("Couldn't create reasoner info instance for extension '%s'.", reasonerId);
}
final ProtegeOWLReasonerInfo reasonerInfo;
try {
reasonerInfo = (ProtegeOWLReasonerInfo) classElement.get().createExecutableExtension(VALUE_ATTRIBUTE);
reasonerInfo.initialise();
} catch (final Exception e) {
throw new ReasonerApiException("Couldn't create reasoner info instance for extension '%s'.", reasonerId, e);
}
final OWLReasonerFactory reasonerFactory = reasonerInfo.getReasonerFactory();
final OWLReasonerConfiguration reasonerConfiguration = reasonerInfo.getConfiguration(new LoggingProgressMonitor(LOGGER));
return reasonerFactory.createNonBufferingReasoner(owlOntology, reasonerConfiguration);
}
}
throw new ReasonerApiException("Couldn't create reasoner info instance for extension '%s'.", reasonerId);
}
use of com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException in project snow-owl by b2ihealthcare.
the class EquivalencyChecker method processResults.
@Override
protected LongKeyLongMap processResults(final String classificationId) {
final Set<String> conceptIdsToCheck = additionalConcepts.stream().map(SnomedConcept::getId).collect(Collectors.toSet());
final LongKeyLongMap equivalentConceptMap = PrimitiveMaps.newLongKeyLongOpenHashMap();
final ClassificationTask classificationTask = ClassificationRequests.prepareGetClassification(classificationId).setExpand("equivalentConceptSets()").build(repositoryId).execute(getEventBus()).getSync();
if (!ClassificationStatus.COMPLETED.equals(classificationTask.getStatus())) {
throw new ReasonerApiException("Selected reasoner could not start or failed to finish its job.");
}
if (!classificationTask.getEquivalentConceptsFound()) {
return equivalentConceptMap;
}
final EquivalentConceptSets equivalentConceptSets = classificationTask.getEquivalentConceptSets();
registerEquivalentConcepts(equivalentConceptSets, conceptIdsToCheck, equivalentConceptMap);
return equivalentConceptMap;
}
Aggregations