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