use of com.b2international.snowowl.snomed.datastore.index.taxonomy.ReasonerTaxonomyBuilder in project snow-owl by b2ihealthcare.
the class ClassificationJobRequest method buildTaxonomy.
private ReasonerTaxonomy buildTaxonomy(final RevisionSearcher revisionSearcher, final Set<String> excludedModuleIds, final boolean concreteDomainSupported) {
final ReasonerTaxonomyBuilder taxonomyBuilder = new ReasonerTaxonomyBuilder(excludedModuleIds);
taxonomyBuilder.addActiveConceptIds(revisionSearcher);
taxonomyBuilder.addActiveConceptIds(additionalConcepts.stream());
taxonomyBuilder.finishConcepts();
taxonomyBuilder.addConceptFlags(revisionSearcher);
taxonomyBuilder.addActiveStatedEdges(revisionSearcher);
taxonomyBuilder.addActiveStatedRelationships(revisionSearcher);
taxonomyBuilder.addActiveInferredRelationships(revisionSearcher);
taxonomyBuilder.addActiveAdditionalGroupedRelationships(revisionSearcher);
taxonomyBuilder.addNeverGroupedTypeIds(revisionSearcher);
taxonomyBuilder.addActiveAxioms(revisionSearcher);
if (concreteDomainSupported) {
taxonomyBuilder.addActiveConcreteDomainMembers(revisionSearcher);
}
// Add the extra definitions
taxonomyBuilder.addConceptFlags(additionalConcepts.stream());
final Supplier<Stream<SnomedRelationship>> relationshipSupplier = () -> additionalConcepts.stream().flatMap(c -> c.getRelationships().stream());
taxonomyBuilder.addActiveStatedEdges(relationshipSupplier.get());
taxonomyBuilder.addActiveStatedRelationships(relationshipSupplier.get());
taxonomyBuilder.addActiveInferredRelationships(relationshipSupplier.get());
taxonomyBuilder.addActiveAdditionalGroupedRelationships(relationshipSupplier.get());
if (concreteDomainSupported) {
final Stream<SnomedReferenceSetMember> conceptMembers = additionalConcepts.stream().flatMap(c -> c.getMembers().stream());
taxonomyBuilder.addActiveConcreteDomainMembers(conceptMembers);
}
return taxonomyBuilder.build();
}
use of com.b2international.snowowl.snomed.datastore.index.taxonomy.ReasonerTaxonomyBuilder in project snow-owl by b2ihealthcare.
the class OntologyExportRequest method execute.
@Override
public String execute(final BranchContext context) {
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 concreteDomainSupportEnabled = configuration.isConcreteDomainSupported();
final ReasonerTaxonomyBuilder taxonomyBuilder = new ReasonerTaxonomyBuilder(reasonerExcludedModuleIds);
taxonomyBuilder.addActiveConceptIds(revisionSearcher);
taxonomyBuilder.finishConcepts();
taxonomyBuilder.addFullySpecifiedNames(revisionSearcher);
taxonomyBuilder.addConceptFlags(revisionSearcher);
taxonomyBuilder.addActiveStatedEdges(revisionSearcher);
taxonomyBuilder.addActiveStatedRelationships(revisionSearcher);
taxonomyBuilder.addNeverGroupedTypeIds(revisionSearcher);
taxonomyBuilder.addActiveAxioms(revisionSearcher);
if (concreteDomainSupportEnabled) {
taxonomyBuilder.addActiveConcreteDomainMembers(revisionSearcher);
}
final ReasonerTaxonomy taxonomy = taxonomyBuilder.build();
final OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
ontologyManager.getOntologyFactories().add(new DelegateOntologyFactory(taxonomy));
final IRI ontologyIRI = IRI.create(DelegateOntology.NAMESPACE_SCTM + ontologyModuleId);
try {
final OWLOntology ontology = ontologyManager.createOntology(ontologyIRI);
OWLOntology ontologyToExport = ontologyManager.createOntology();
ontology.getAxioms().forEach(axiom -> {
ontologyManager.addAxiom(ontologyToExport, axiom);
});
final OWLDocumentFormat documentFormat = getOWLDocumentFormat();
final AttachmentRegistry fileRegistry = context.service(AttachmentRegistry.class);
final UUID id = UUID.randomUUID();
final PipedOutputStream os = new PipedOutputStream();
final PipedInputStream is = new PipedInputStream(os, PIPE_SIZE);
final ForkJoinTask<?> uploadTask = ForkJoinTask.adapt(() -> fileRegistry.upload(id, is));
final ForkJoinTask<?> saveTask = ForkJoinTask.adapt(() -> {
try {
ontologyManager.saveOntology(ontologyToExport, documentFormat, os);
} catch (final OWLOntologyStorageException e) {
throw createExportFailedException(context, e);
} finally {
try {
os.close();
} catch (final IOException e) {
throw createExportFailedException(context, e);
}
}
});
ForkJoinTask.invokeAll(saveTask, uploadTask);
return id.toString();
} catch (final OWLOntologyCreationException e) {
throw createExportFailedException(context, e);
} catch (final IOException e) {
throw createExportFailedException(context, e);
} finally {
// invalidate static cache entries :'(
ontologyManager.getOntologies().forEach(o -> {
ontologyManager.applyChange(new SetOntologyID(o, new OWLOntologyID()));
});
}
}
Aggregations