Search in sources :

Example 31 with SnomedRefSetMemberIndexEntry

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

the class SnomedComplexMapMemberCreateDelegate method execute.

@Override
public String execute(SnomedReferenceSet refSet, TransactionContext context) {
    checkRefSetType(refSet, SnomedRefSetType.COMPLEX_MAP);
    checkReferencedComponent(refSet);
    checkHasProperty(SnomedRf2Headers.FIELD_MAP_GROUP);
    checkHasProperty(SnomedRf2Headers.FIELD_MAP_PRIORITY);
    checkHasProperty(SnomedRf2Headers.FIELD_MAP_RULE);
    checkHasProperty(SnomedRf2Headers.FIELD_MAP_ADVICE);
    checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MODULE_ID, getModuleId());
    checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, getReferencedComponentId());
    checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_CORRELATION_ID);
    if (SnomedIdentifiers.isValid(getProperty(SnomedRf2Headers.FIELD_MAP_TARGET))) {
        checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MAP_TARGET);
    }
    SnomedRefSetMemberIndexEntry member = SnomedComponents.newComplexMapMember().withId(getId()).withActive(isActive()).withReferencedComponent(getReferencedComponentId()).withModuleId(getModuleId()).withRefSet(getReferenceSetId()).withMapTargetId(getComponentId(SnomedRf2Headers.FIELD_MAP_TARGET)).withGroup(getProperty(SnomedRf2Headers.FIELD_MAP_GROUP, Integer.class)).withPriority(getProperty(SnomedRf2Headers.FIELD_MAP_PRIORITY, Integer.class)).withMapRule(getProperty(SnomedRf2Headers.FIELD_MAP_RULE)).withMapAdvice(getProperty(SnomedRf2Headers.FIELD_MAP_ADVICE)).withCorrelationId(getComponentId(SnomedRf2Headers.FIELD_CORRELATION_ID)).addTo(context);
    return member.getId();
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)

Example 32 with SnomedRefSetMemberIndexEntry

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

the class SnomedEclRefinementEvaluator method evalAxiomStatements.

static Set<Property> evalAxiomStatements(final BranchContext context, final boolean groupedRelationshipsOnly, final Collection<String> sourceIds, final Collection<String> typeIds, final Collection<String> destinationIds) {
    try {
        // search existing axioms (no values!) defined for the given set of conceptIds
        ExpressionBuilder axiomFilter = Expressions.builder().filter(hasDestinationId());
        if (typeIds != null) {
            axiomFilter.filter(typeIds(typeIds));
        }
        if (destinationIds != null) {
            axiomFilter.filter(destinationIds(destinationIds));
        }
        if (groupedRelationshipsOnly) {
            axiomFilter.filter(relationshipGroup(1, Integer.MAX_VALUE));
        }
        ExpressionBuilder activeOwlAxiomMemberQuery = Expressions.builder().filter(active()).filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, axiomFilter.build()));
        if (sourceIds != null) {
            activeOwlAxiomMemberQuery.filter(SnomedRefSetMemberIndexEntry.Expressions.referencedComponentIds(sourceIds));
        }
        final Query<SnomedRefSetMemberIndexEntry> activeAxiomStatementsQuery = Query.select(SnomedRefSetMemberIndexEntry.class).where(activeOwlAxiomMemberQuery.build()).limit(Integer.MAX_VALUE).build();
        return context.service(RevisionSearcher.class).search(activeAxiomStatementsQuery).stream().filter(owlMember -> !CompareUtils.isEmpty(owlMember.getClassAxiomRelationships())).flatMap(owlMember -> {
            return owlMember.getClassAxiomRelationships().stream().filter(classAxiom -> {
                return (typeIds == null || typeIds.contains(classAxiom.getTypeId())) && (destinationIds == null || destinationIds.contains(classAxiom.getDestinationId())) && (!groupedRelationshipsOnly || classAxiom.getRelationshipGroup() >= 1);
            }).map(classAxiom -> {
                return new Property(owlMember.getReferencedComponentId(), classAxiom.getTypeId(), classAxiom.getDestinationId(), classAxiom.getRelationshipGroup());
            });
        }).collect(Collectors.toSet());
    } catch (IOException e) {
        throw new SnowowlRuntimeException(e);
    }
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) 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) IOException(java.io.IOException) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 33 with SnomedRefSetMemberIndexEntry

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

the class SnomedEclRefinementEvaluator method evalAxiomsWithValue.

private Promise<Collection<Property>> evalAxiomsWithValue(BranchContext context, Set<String> focusConceptIds, Collection<String> typeIds, RelationshipValue value, SearchResourceRequest.Operator operator) {
    // search existing axioms defined for the given set of conceptIds
    ExpressionBuilder axiomFilter = Expressions.builder();
    if (typeIds != null) {
        axiomFilter.filter(typeIds(typeIds));
    }
    switch(operator) {
        case EQUALS:
            axiomFilter.filter(values(List.of(value)));
            break;
        case GREATER_THAN:
            axiomFilter.filter(valueGreaterThan(value, false));
            break;
        case GREATER_THAN_EQUALS:
            axiomFilter.filter(valueGreaterThan(value, true));
            break;
        case LESS_THAN:
            axiomFilter.filter(valueLessThan(value, false));
            break;
        case LESS_THAN_EQUALS:
            axiomFilter.filter(valueLessThan(value, true));
            break;
        case NOT_EQUALS:
            axiomFilter.mustNot(values(List.of(value)));
            break;
        default:
            throw new IllegalStateException("Unexpected operator '" + operator + "'.");
    }
    ExpressionBuilder activeOwlAxiomMemberQuery = Expressions.builder().filter(active()).filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, axiomFilter.build()));
    if (focusConceptIds != null) {
        activeOwlAxiomMemberQuery.filter(SnomedRefSetMemberIndexEntry.Expressions.referencedComponentIds(focusConceptIds));
    }
    final Query<SnomedRefSetMemberIndexEntry> activeAxiomStatementsQuery = Query.select(SnomedRefSetMemberIndexEntry.class).where(activeOwlAxiomMemberQuery.build()).limit(context.service(RepositoryConfiguration.class).getIndexConfiguration().getResultWindow()).build();
    final Set<Property> axiomProperties = newHashSet();
    context.service(RevisionSearcher.class).stream(activeAxiomStatementsQuery).forEach(chunk -> {
        chunk.stream().filter(owlMember -> !CompareUtils.isEmpty(owlMember.getClassAxiomRelationships())).forEachOrdered(owlMember -> {
            owlMember.getClassAxiomRelationships().stream().filter(r -> typeIds == null || typeIds.contains(r.getTypeId())).filter(r -> r.getValueAsObject().matches(operator, value)).map(r -> new Property(owlMember.getReferencedComponentId(), r.getTypeId(), r.getValueAsObject().toObject(), r.getRelationshipGroup())).forEachOrdered(axiomProperties::add);
        });
    });
    return Promise.immediate(axiomProperties);
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) 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) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder)

Example 34 with SnomedRefSetMemberIndexEntry

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

the class ConceptChangeProcessorAxiomTest method deleteEmpty.

@Test
public void deleteEmpty() throws Exception {
    final SnomedConceptDocument concept = concept().activeMemberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).memberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).build();
    final SnomedRefSetMemberIndexEntry member = createOwlAxiom(concept.getId(), "").build();
    indexRevision(MAIN, concept, member);
    stageRemove(member);
    final ConceptChangeProcessor processor = process();
    assertEquals(1, processor.getChangedMappings().size());
    final SnomedConceptDocument expected = docWithDefaults(concept).build();
    final Revision actual = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
    assertDocEquals(expected, actual);
    assertEquals(0, processor.getNewMappings().size());
    assertEquals(0, processor.getDeletions().size());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Revision(com.b2international.index.revision.Revision) Test(org.junit.Test)

Example 35 with SnomedRefSetMemberIndexEntry

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

the class ConceptChangeProcessorAxiomTest method newSubClassOfAxiom_TwoTargets.

@Test
public void newSubClassOfAxiom_TwoTargets() throws Exception {
    SnomedConceptDocument concept = concept().build();
    SnomedConceptDocument parentConcept = concept().build();
    SnomedConceptDocument parentConcept2 = concept().build();
    indexRevision(MAIN, concept, parentConcept, parentConcept2);
    statedChangedConceptIds.add(Long.parseLong(concept.getId()));
    statedChangedConceptIds.add(Long.parseLong(parentConcept.getId()));
    statedChangedConceptIds.add(Long.parseLong(parentConcept2.getId()));
    SnomedRefSetMemberIndexEntry member = createOwlAxiom(concept.getId(), String.format("SubClassOf(:%s ObjectIntersectionOf(:%s :%s))", concept.getId(), parentConcept.getId(), parentConcept2.getId())).build();
    stageNew(member);
    final ConceptChangeProcessor processor = process();
    assertEquals(1, processor.getChangedMappings().size());
    final SnomedConceptDocument expected = docWithDefaults(concept).statedParents(Long.parseLong(parentConcept.getId()), Long.parseLong(parentConcept2.getId())).statedAncestors(IComponent.ROOT_IDL).activeMemberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).memberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).build();
    final Revision actual = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
    assertDocEquals(expected, actual);
    assertEquals(0, processor.getNewMappings().size());
    assertEquals(0, processor.getDeletions().size());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Revision(com.b2international.index.revision.Revision) Test(org.junit.Test)

Aggregations

SnomedRefSetMemberIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)59 Test (org.junit.Test)29 Revision (com.b2international.index.revision.Revision)28 SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)19 SnomedDescriptionIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry)15 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)8 SnomedRelationshipIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry)8 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)7 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 IOException (java.io.IOException)7 CompareUtils (com.b2international.commons.CompareUtils)5 Expressions (com.b2international.index.query.Expressions)5 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)5 Query (com.b2international.index.query.Query)5 StagingArea (com.b2international.index.revision.StagingArea)5 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)5 SnomedDescriptionFragment (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment)5 Expressions.active (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active)5 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)5 Collection (java.util.Collection)5