Search in sources :

Example 1 with EquivalentConceptSet

use of com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet in project snow-owl by b2ihealthcare.

the class EquivalentConceptSetConverter method expand.

@Override
public void expand(final List<EquivalentConceptSet> results) {
    if (!expand().containsKey(EquivalentConceptSet.Expand.EQUIVALENT_CONCEPTS)) {
        return;
    }
    final Set<String> classificationTaskIds = results.stream().map(EquivalentConceptSet::getClassificationId).collect(Collectors.toSet());
    final Map<String, String> branchesByClassificationIdMap = ClassificationRequests.prepareSearchClassification().filterByIds(classificationTaskIds).all().build().execute(context()).stream().collect(Collectors.toMap(ClassificationTask::getId, ClassificationTask::getBranch));
    final Multimap<String, EquivalentConceptSet> itemsByBranch = Multimaps.index(results, r -> branchesByClassificationIdMap.get(r.getClassificationId()));
    final Options expandOptions = expand().get(EquivalentConceptSet.Expand.EQUIVALENT_CONCEPTS, Options.class);
    for (final String branch : itemsByBranch.keySet()) {
        final Collection<EquivalentConceptSet> itemsForCurrentBranch = itemsByBranch.get(branch);
        final Set<String> conceptIds = itemsForCurrentBranch.stream().flatMap(c -> c.getEquivalentConcepts().stream()).map(SnomedConcept::getId).collect(Collectors.toSet());
        final SnomedConcepts concepts = SnomedRequests.prepareSearchConcept().filterByIds(conceptIds).all().setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).build(branch).getRequest().execute(context());
        final Map<String, SnomedConcept> conceptsById = Maps.uniqueIndex(concepts, SnomedConcept::getId);
        for (final EquivalentConceptSet item : itemsForCurrentBranch) {
            final List<SnomedConcept> equivalentConcepts = item.getEquivalentConcepts().getItems();
            for (int i = 0; i < equivalentConcepts.size(); i++) {
                final SnomedConcept placeholderConcept = equivalentConcepts.get(i);
                final SnomedConcept expandedConcept = conceptsById.get(placeholderConcept.getId());
                equivalentConcepts.set(i, expandedConcept);
            }
        }
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) EquivalentConceptSet(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 2 with EquivalentConceptSet

use of com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet in project snow-owl by b2ihealthcare.

the class ClassificationTaskConverter method expandEquivalentConceptSets.

private void expandEquivalentConceptSets(final List<ClassificationTask> results, final Set<String> classificationTaskIds) {
    if (!expand().containsKey(ClassificationTask.Expand.EQUIVALENT_CONCEPT_SETS)) {
        return;
    }
    final Options expandOptions = expand().get(ClassificationTask.Expand.EQUIVALENT_CONCEPT_SETS, Options.class);
    final EquivalentConceptSets equivalentConceptSets = ClassificationRequests.prepareSearchEquivalentConceptSet().filterByClassificationId(classificationTaskIds).all().setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).build().execute(context());
    final ListMultimap<String, EquivalentConceptSet> setsByTaskId = Multimaps.index(equivalentConceptSets, EquivalentConceptSet::getClassificationId);
    for (final ClassificationTask classificationTask : results) {
        final List<EquivalentConceptSet> taskSets = setsByTaskId.get(classificationTask.getId());
        classificationTask.setEquivalentConceptSets(new EquivalentConceptSets(taskSets, null, taskSets.size(), taskSets.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options) EquivalentConceptSets(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSets) ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask) EquivalentConceptSet(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet)

Example 3 with EquivalentConceptSet

use of com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet in project snow-owl by b2ihealthcare.

the class EquivalentConceptSetConverter method toResource.

@Override
protected EquivalentConceptSet toResource(final EquivalentConceptSetDocument entry) {
    final EquivalentConceptSet resource = new EquivalentConceptSet();
    resource.setClassificationId(entry.getClassificationId());
    resource.setUnsatisfiable(entry.isUnsatisfiable());
    final List<SnomedConcept> items = newArrayList();
    for (final LongIterator itr = entry.getConceptIds().iterator(); itr.hasNext(); ) /* empty */
    {
        items.add(new SnomedConcept(Long.toString(itr.next())));
    }
    final SnomedConcepts equivalentConcepts = new SnomedConcepts(items, null, items.size(), items.size());
    resource.setEquivalentConcepts(equivalentConcepts);
    return resource;
}
Also used : SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) EquivalentConceptSet(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) LongIterator(com.b2international.collections.longs.LongIterator)

Example 4 with EquivalentConceptSet

use of com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet in project snow-owl by b2ihealthcare.

the class EquivalencyChecker method registerEquivalentConcepts.

private void registerEquivalentConcepts(final EquivalentConceptSets equivalentConceptSets, final Set<String> conceptIdsToCheck, final LongKeyLongMap equivalentConceptMap) {
    for (final EquivalentConceptSet equivalenceSet : equivalentConceptSets) {
        if (equivalenceSet.isUnsatisfiable()) {
            continue;
        }
        final String suggestedConceptId = equivalenceSet.getEquivalentConcepts().first().map(SnomedConcept::getId).get();
        final Set<String> equivalentIds = equivalenceSet.getEquivalentConcepts().stream().map(SnomedConcept::getId).collect(Collectors.toSet());
        equivalentIds.remove(suggestedConceptId);
        if (!conceptIdsToCheck.isEmpty()) {
            equivalentIds.retainAll(conceptIdsToCheck);
        }
        registerEquivalentConcepts(suggestedConceptId, equivalentIds, equivalentConceptMap, conceptIdsToCheck);
    }
}
Also used : EquivalentConceptSet(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet)

Aggregations

EquivalentConceptSet (com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet)4 Options (com.b2international.commons.options.Options)2 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)2 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)2 LongIterator (com.b2international.collections.longs.LongIterator)1 ClassificationTask (com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask)1 EquivalentConceptSets (com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSets)1