use of com.b2international.snowowl.snomed.core.domain.SnomedRelationships in project snow-owl by b2ihealthcare.
the class EclExpression method resolveToGroupedOnly.
private Promise<Multimap<String, Integer>> resolveToGroupedOnly(BranchContext context, Set<String> sourceIds) {
final Set<String> characteristicTypes = isInferred() ? SnomedEclRefinementEvaluator.INFERRED_CHARACTERISTIC_TYPES : SnomedEclRefinementEvaluator.STATED_CHARACTERISTIC_TYPES;
List<Promise<Multimap<String, Integer>>> promises = newArrayListWithCapacity(3);
// search relationships
promises.add(SnomedRequests.prepareSearchRelationship().all().filterByActive(true).filterByCharacteristicTypes(characteristicTypes).filterBySources(sourceIds).filterByGroup(1, Integer.MAX_VALUE).setEclExpressionForm(expressionForm).setFields(SnomedRelationshipIndexEntry.Fields.ID, SnomedRelationshipIndexEntry.Fields.SOURCE_ID, SnomedRelationshipIndexEntry.Fields.RELATIONSHIP_GROUP).build(context.service(ResourceURI.class)).execute(context.service(IEventBus.class)).then(new Function<SnomedRelationships, Multimap<String, Integer>>() {
@Override
public Multimap<String, Integer> apply(SnomedRelationships input) {
final Multimap<String, SnomedRelationship> relationshipsBySource = Multimaps.index(input, SnomedRelationship::getSourceId);
final Multimap<String, Integer> groupsByRelationshipId = Multimaps.transformValues(relationshipsBySource, SnomedRelationship::getRelationshipGroup);
return ImmutableSetMultimap.copyOf(groupsByRelationshipId);
}
}));
// search concrete domain members
if (context.service(SnomedCoreConfiguration.class).isConcreteDomainSupported()) {
final Options propFilter = Options.builder().put(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID, characteristicTypes).put(SearchResourceRequest.operator(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP), SearchResourceRequest.Operator.NOT_EQUALS).put(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP, 0).build();
promises.add(SnomedRequests.prepareSearchMember().all().filterByActive(true).filterByReferencedComponent(sourceIds).filterByRefSetType(SnomedRefSetType.CONCRETE_DATA_TYPE).filterByProps(propFilter).setEclExpressionForm(expressionForm).build(context.service(ResourceURI.class)).execute(context.service(IEventBus.class)).then(members -> {
final Multimap<String, SnomedReferenceSetMember> relationshipsBySource = Multimaps.index(members, m -> m.getReferencedComponent().getId());
return Multimaps.transformValues(relationshipsBySource, m -> (Integer) m.getProperties().get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP));
}));
} else {
promises.add(Promise.immediate(ImmutableSetMultimap.of()));
}
// search owl axiom members
if (isStated()) {
ImmutableSetMultimap.Builder<String, Integer> groupedAxioms = ImmutableSetMultimap.builder();
SnomedEclRefinementEvaluator.evalAxiomStatements(context, true, sourceIds, null, null).forEach(property -> groupedAxioms.put(property.getObjectId(), property.getGroup()));
promises.add(Promise.immediate(groupedAxioms.build()));
} else {
promises.add(Promise.immediate(ImmutableSetMultimap.of()));
}
return Promise.all(promises).then(statements -> {
Multimap<String, Integer> relationshipStatements = (Multimap<String, Integer>) statements.get(0);
Multimap<String, Integer> concreteDomainStatements = (Multimap<String, Integer>) statements.get(1);
Multimap<String, Integer> axiomStatements = (Multimap<String, Integer>) statements.get(2);
return ImmutableSetMultimap.<String, Integer>builder().putAll(relationshipStatements).putAll(concreteDomainStatements).putAll(axiomStatements).build();
});
}
Aggregations