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();
}
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);
}
}
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);
}
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());
}
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());
}
Aggregations