Search in sources :

Example 1 with Expressions

use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions in project snow-owl by b2ihealthcare.

the class SnomedEclRefinementEvaluator method evalRefinement.

/**
 * Evaluates an {@link AttributeConstraint} refinement on the given focusConceptId set on the given {@link BranchContext}.
 * Grouped parameter can
 */
private Promise<Collection<Property>> evalRefinement(final BranchContext context, final AttributeConstraint refinement, final boolean grouped, final Set<String> focusConceptIds) {
    final Comparison comparison = refinement.getComparison();
    final Collection<String> typeConceptFilter = evalToConceptIds(context, refinement.getAttribute(), expressionForm).getSync(1, TimeUnit.MINUTES);
    if (comparison instanceof AttributeComparison) {
        // resolve non-* focusConcept ECLs to IDs, so we can filter relationships by source/destination
        // filterByType and filterByDestination accepts ECL expressions as well, so serialize them into ECL and pass as String when required
        // if reversed refinement, then we are interested in the destinationIds otherwise we need the sourceIds
        final Collection<String> destinationConceptFilter = evalToConceptIds(context, ((AttributeComparison) comparison).getValue(), expressionForm).getSync(1, TimeUnit.MINUTES);
        final Collection<String> focusConceptFilter = refinement.isReversed() ? destinationConceptFilter : focusConceptIds;
        final Collection<String> valueConceptFilter = refinement.isReversed() ? focusConceptIds : destinationConceptFilter;
        return evalStatements(context, focusConceptFilter, typeConceptFilter, valueConceptFilter, grouped, expressionForm);
    } else if (comparison instanceof DataTypeComparison) {
        if (refinement.isReversed()) {
            throw new BadRequestException("Reversed flag is not supported in data type based comparison (string/numeric)");
        } else {
            final Promise<Collection<Property>> statementsWithValue = evalStatementsWithValue(context, focusConceptIds, typeConceptFilter, (DataTypeComparison) comparison);
            final Promise<Collection<Property>> members = evalMembers(context, focusConceptIds, typeConceptFilter, (DataTypeComparison) comparison);
            return Promise.all(statementsWithValue, members).then(results -> {
                final Collection<Property> s = (Collection<Property>) results.get(0);
                final Collection<Property> m = (Collection<Property>) results.get(1);
                return FluentIterable.concat(s, m).toSet();
            });
        }
    } else {
        return SnomedEclEvaluationRequest.throwUnsupported(comparison);
    }
}
Also used : PolymorphicDispatcher(org.eclipse.xtext.util.PolymorphicDispatcher) Query(com.b2international.index.query.Query) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Promise(com.b2international.snowowl.core.events.util.Promise) ID(com.b2international.index.revision.Revision.Fields.ID) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) com.b2international.snomed.ecl.ecl(com.b2international.snomed.ecl.ecl) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) CompareUtils(com.b2international.commons.CompareUtils) com.google.common.collect(com.google.common.collect) ResourceURI(com.b2international.snowowl.core.ResourceURI) BadRequestException(com.b2international.commons.exceptions.BadRequestException) Function(com.google.common.base.Function) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) Collection(java.util.Collection) SnomedRelationshipSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRelationshipSearchRequestBuilder) DataType(com.b2international.snowowl.snomed.core.domain.refset.DataType) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) Trees(com.b2international.snowowl.snomed.core.tree.Trees) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Expressions(com.b2international.index.query.Expressions) Expressions.active(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active) Entry(java.util.Map.Entry) Expression(com.b2international.index.query.Expression) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Fields(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Fields) Expressions(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) Promise(com.b2international.snowowl.core.events.util.Promise) BadRequestException(com.b2international.commons.exceptions.BadRequestException) Collection(java.util.Collection)

Aggregations

CompareUtils (com.b2international.commons.CompareUtils)1 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 Options (com.b2international.commons.options.Options)1 Expression (com.b2international.index.query.Expression)1 Expressions (com.b2international.index.query.Expressions)1 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1 Query (com.b2international.index.query.Query)1 ID (com.b2international.index.revision.Revision.Fields.ID)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 com.b2international.snomed.ecl.ecl (com.b2international.snomed.ecl.ecl)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 Promise (com.b2international.snowowl.core.events.util.Promise)1 SearchResourceRequest (com.b2international.snowowl.core.request.SearchResourceRequest)1 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)1 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)1 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)1 DataType (com.b2international.snowowl.snomed.core.domain.refset.DataType)1