Search in sources :

Example 1 with com.b2international.snomed.ecl.ecl

use of com.b2international.snomed.ecl.ecl in project snow-owl by b2ihealthcare.

the class SnomedEclEvaluationRequest method eval.

/**
 * Handles (possibly) filtered expression constraints by evaluating them along
 * with the primary ECL expression, and adding the resulting query expressions as
 * extra required clauses.
 *
 * @param context
 * @param filtered
 * @return
 */
protected Promise<Expression> eval(BranchContext context, final FilteredExpressionConstraint filtered) {
    final ExpressionConstraint constraint = filtered.getConstraint();
    final FilterConstraint filterConstraint = filtered.getFilter();
    final Domain filterDomain = Ecl.getDomain(filterConstraint);
    final Filter filter = filterConstraint.getFilter();
    final Promise<Expression> evaluatedConstraint = evaluate(context, constraint);
    Promise<Expression> evaluatedFilter = evaluate(context, filter);
    if (Domain.DESCRIPTION.equals(filterDomain)) {
        // Find concepts that match the description expression, then use the resulting concept IDs as the expression
        evaluatedFilter = evaluatedFilter.then(ex -> executeDescriptionSearch(context, ex));
    }
    if (isAnyExpression(constraint)) {
        // No need to combine "match all" with the filter query expression, return it directly
        return evaluatedFilter;
    }
    return Promise.all(evaluatedConstraint, evaluatedFilter).then(results -> {
        final Expressions.ExpressionBuilder builder = Expressions.builder();
        results.forEach(f -> builder.filter((Expression) f));
        return builder.build();
    });
}
Also used : PolymorphicDispatcher(org.eclipse.xtext.util.PolymorphicDispatcher) EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) java.util(java.util) Hits(com.b2international.index.Hits) Promise(com.b2international.snowowl.core.events.util.Promise) ID(com.b2international.index.revision.Revision.Fields.ID) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedDescriptionUtils(com.b2international.snowowl.snomed.datastore.SnomedDescriptionUtils) SnomedDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument) Expressions.ids(com.b2international.index.revision.Revision.Expressions.ids) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Predicates(com.google.common.base.Predicates) com.b2international.snomed.ecl.ecl(com.b2international.snomed.ecl.ecl) CompareUtils(com.b2international.commons.CompareUtils) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) TreeIterator(org.eclipse.emf.common.util.TreeIterator) com.google.common.collect(com.google.common.collect) Nullable(javax.annotation.Nullable) DateFormats(com.b2international.snowowl.core.date.DateFormats) Function(com.google.common.base.Function) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Request(com.b2international.snowowl.core.events.Request) EclExpression.isEclConceptReference(com.b2international.snowowl.snomed.core.ecl.EclExpression.isEclConceptReference) IOException(java.io.IOException) EObject(org.eclipse.emf.ecore.EObject) EclExpression.isAnyExpression(com.b2international.snowowl.snomed.core.ecl.EclExpression.isAnyExpression) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Trees(com.b2international.snowowl.snomed.core.tree.Trees) ACTIVE_MEMBER_OF(com.b2international.snowowl.snomed.datastore.index.entry.SnomedComponentDocument.Fields.ACTIVE_MEMBER_OF) TimeUnit(java.util.concurrent.TimeUnit) Expressions.id(com.b2international.index.revision.Revision.Expressions.id) IComponent(com.b2international.snowowl.core.domain.IComponent) Expressions.activeMemberOf(com.b2international.snowowl.snomed.datastore.index.entry.SnomedComponentDocument.Expressions.activeMemberOf) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) Ecl(com.b2international.snomed.ecl.Ecl) BranchContext(com.b2international.snowowl.core.domain.BranchContext) NotImplementedException(com.b2international.commons.exceptions.NotImplementedException) com.b2international.index.query(com.b2international.index.query) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) EclExpression.isAnyExpression(com.b2international.snowowl.snomed.core.ecl.EclExpression.isAnyExpression)

Example 2 with com.b2international.snomed.ecl.ecl

use of com.b2international.snomed.ecl.ecl 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)2 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)2 ID (com.b2international.index.revision.Revision.Fields.ID)2 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)2 com.b2international.snomed.ecl.ecl (com.b2international.snomed.ecl.ecl)2 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)2 BranchContext (com.b2international.snowowl.core.domain.BranchContext)2 Promise (com.b2international.snowowl.core.events.util.Promise)2 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)2 Trees (com.b2international.snowowl.snomed.core.tree.Trees)2 SnomedDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument)2 Function (com.google.common.base.Function)2 com.google.common.collect (com.google.common.collect)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 IOException (java.io.IOException)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2 PolymorphicDispatcher (org.eclipse.xtext.util.PolymorphicDispatcher)2 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 NotImplementedException (com.b2international.commons.exceptions.NotImplementedException)1