Search in sources :

Example 1 with SnomedRelationships

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();
    });
}
Also used : Query(com.b2international.index.query.Query) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Promise(com.b2international.snowowl.core.events.util.Promise) Multimap(com.google.common.collect.Multimap) Multimaps(com.google.common.collect.Multimaps) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) NestedExpression(com.b2international.snomed.ecl.ecl.NestedExpression) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Nullable(javax.annotation.Nullable) ResourceURI(com.b2international.snowowl.core.ResourceURI) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Lists.newArrayListWithCapacity(com.google.common.collect.Lists.newArrayListWithCapacity) Function(com.google.common.base.Function) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) RevisionDocument(com.b2international.snowowl.core.repository.RevisionDocument) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) Set(java.util.Set) IOException(java.io.IOException) IEventBus(com.b2international.snowowl.eventbus.IEventBus) NotNull(javax.validation.constraints.NotNull) PathWithVersion(com.b2international.snowowl.core.uri.ResourceURIPathResolver.PathWithVersion) SnomedRelationships(com.b2international.snowowl.snomed.core.domain.SnomedRelationships) Any(com.b2international.snomed.ecl.ecl.Any) Trees(com.b2international.snowowl.snomed.core.tree.Trees) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) List(java.util.List) Expressions(com.b2international.index.query.Expressions) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Expression(com.b2international.index.query.Expression) Preconditions(com.google.common.base.Preconditions) Ecl(com.b2international.snomed.ecl.Ecl) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) EclConceptReference(com.b2international.snomed.ecl.ecl.EclConceptReference) ExpressionConstraint(com.b2international.snomed.ecl.ecl.ExpressionConstraint) BranchContext(com.b2international.snowowl.core.domain.BranchContext) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedCoreConfiguration(com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration) Options(com.b2international.commons.options.Options) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) SnomedCoreConfiguration(com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration) SnomedRelationships(com.b2international.snowowl.snomed.core.domain.SnomedRelationships) Promise(com.b2international.snowowl.core.events.util.Promise) Function(com.google.common.base.Function) Multimap(com.google.common.collect.Multimap) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) IEventBus(com.b2international.snowowl.eventbus.IEventBus)

Aggregations

Options (com.b2international.commons.options.Options)1 Expression (com.b2international.index.query.Expression)1 Expressions (com.b2international.index.query.Expressions)1 Query (com.b2international.index.query.Query)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 Ecl (com.b2international.snomed.ecl.Ecl)1 Any (com.b2international.snomed.ecl.ecl.Any)1 EclConceptReference (com.b2international.snomed.ecl.ecl.EclConceptReference)1 ExpressionConstraint (com.b2international.snomed.ecl.ecl.ExpressionConstraint)1 NestedExpression (com.b2international.snomed.ecl.ecl.NestedExpression)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 Promise (com.b2international.snowowl.core.events.util.Promise)1 RevisionDocument (com.b2international.snowowl.core.repository.RevisionDocument)1 SearchResourceRequest (com.b2international.snowowl.core.request.SearchResourceRequest)1 PathWithVersion (com.b2international.snowowl.core.uri.ResourceURIPathResolver.PathWithVersion)1 IEventBus (com.b2international.snowowl.eventbus.IEventBus)1 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)1 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)1