use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember 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();
});
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class SnomedVersioningRequest method adjustDependencyRefSetMembers.
private void adjustDependencyRefSetMembers(TransactionContext context, Multimap<String, String> moduleDependencies, Map<String, Long> moduleToLatestEffectiveTime, long effectiveTime) {
// Update existing, add new members to moduleDependencyRefSet
if (!CompareUtils.isEmpty(moduleDependencies)) {
moduleDependencies.entries().forEach((entry) -> {
final String source = entry.getKey();
final String target = entry.getValue();
final SnomedReferenceSetMember existingLatestMember = SnomedRequests.prepareSearchMember().all().filterByModule(source).filterByReferencedComponent(target).filterByRefSet(Concepts.REFSET_MODULE_DEPENDENCY_TYPE).build().execute(context).stream().sorted((o1, o2) -> {
if (null == o1.getEffectiveTime() && null == o2.getEffectiveTime()) {
return 0;
} else if (null == o1.getEffectiveTime() && null != o2.getEffectiveTime()) {
return 1;
} else if (null != o1.getEffectiveTime() && null == o2.getEffectiveTime()) {
return -1;
}
return o1.getEffectiveTime().compareTo(o2.getEffectiveTime());
}).reduce((first, second) -> second).orElse(null);
final SnomedRefSetMemberIndexEntry.Builder updatedMember;
if (existingLatestMember == null) {
updatedMember = SnomedRefSetMemberIndexEntry.builder().id(UUID.randomUUID().toString()).active(true).refsetId(Concepts.REFSET_MODULE_DEPENDENCY_TYPE).referenceSetType(SnomedRefSetType.MODULE_DEPENDENCY).moduleId(source).referencedComponentId(target);
} else {
updatedMember = SnomedRefSetMemberIndexEntry.builder(existingLatestMember);
}
final long targetEffectiveTime = moduleToLatestEffectiveTime.get(target) == EffectiveTimes.UNSET_EFFECTIVE_TIME ? effectiveTime : moduleToLatestEffectiveTime.get(target);
updatedMember.released(true).effectiveTime(effectiveTime).field(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME, effectiveTime).field(SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME, targetEffectiveTime);
if (existingLatestMember == null) {
context.add(updatedMember.build());
} else {
context.update(SnomedRefSetMemberIndexEntry.builder(existingLatestMember).build(), updatedMember.build());
}
});
}
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class ClassificationJobRequest method buildTaxonomy.
private ReasonerTaxonomy buildTaxonomy(final RevisionSearcher revisionSearcher, final Set<String> excludedModuleIds, final boolean concreteDomainSupported) {
final ReasonerTaxonomyBuilder taxonomyBuilder = new ReasonerTaxonomyBuilder(excludedModuleIds);
taxonomyBuilder.addActiveConceptIds(revisionSearcher);
taxonomyBuilder.addActiveConceptIds(additionalConcepts.stream());
taxonomyBuilder.finishConcepts();
taxonomyBuilder.addConceptFlags(revisionSearcher);
taxonomyBuilder.addActiveStatedEdges(revisionSearcher);
taxonomyBuilder.addActiveStatedRelationships(revisionSearcher);
taxonomyBuilder.addActiveInferredRelationships(revisionSearcher);
taxonomyBuilder.addActiveAdditionalGroupedRelationships(revisionSearcher);
taxonomyBuilder.addNeverGroupedTypeIds(revisionSearcher);
taxonomyBuilder.addActiveAxioms(revisionSearcher);
if (concreteDomainSupported) {
taxonomyBuilder.addActiveConcreteDomainMembers(revisionSearcher);
}
// Add the extra definitions
taxonomyBuilder.addConceptFlags(additionalConcepts.stream());
final Supplier<Stream<SnomedRelationship>> relationshipSupplier = () -> additionalConcepts.stream().flatMap(c -> c.getRelationships().stream());
taxonomyBuilder.addActiveStatedEdges(relationshipSupplier.get());
taxonomyBuilder.addActiveStatedRelationships(relationshipSupplier.get());
taxonomyBuilder.addActiveInferredRelationships(relationshipSupplier.get());
taxonomyBuilder.addActiveAdditionalGroupedRelationships(relationshipSupplier.get());
if (concreteDomainSupported) {
final Stream<SnomedReferenceSetMember> conceptMembers = additionalConcepts.stream().flatMap(c -> c.getMembers().stream());
taxonomyBuilder.addActiveConcreteDomainMembers(conceptMembers);
}
return taxonomyBuilder.build();
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class SnomedReferenceSetMemberConverter method toResource.
@Override
protected SnomedReferenceSetMember toResource(SnomedRefSetMemberIndexEntry entry) {
final SnomedReferenceSetMember member = new SnomedReferenceSetMember();
member.setId(entry.getId());
member.setEffectiveTime(toEffectiveTime(entry.getEffectiveTime()));
member.setReleased(entry.isReleased());
member.setActive(entry.isActive());
member.setModuleId(entry.getModuleId());
member.setIconId(entry.getIconId());
member.setRefsetId(entry.getRefsetId());
member.setType(entry.getReferenceSetType());
member.setScore(entry.getScore());
final Map<String, Object> props = newHashMap(entry.getAdditionalFields());
// convert stored long values to short date format
props.computeIfPresent(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME, (key, currentValue) -> toEffectiveTime((long) currentValue));
props.computeIfPresent(SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME, (key, currentValue) -> toEffectiveTime((long) currentValue));
// convert concrete domain value to serialized String format
if (entry.getValue() != null) {
props.put(SnomedRf2Headers.FIELD_VALUE, SnomedRefSetUtil.serializeValue(entry.getDataType(), entry.getValue()));
}
member.setProperties(props);
String owlExpression = entry.getOwlExpression();
if (Concepts.REFSET_OWL_AXIOM.equals(entry.getRefsetId()) && expand().containsKey("owlRelationships") && !Strings.isNullOrEmpty(owlExpression)) {
if (!CompareUtils.isEmpty(entry.getClassAxiomRelationships())) {
if (owlExpression.startsWith("EquivalentClasses")) {
member.setEquivalentOWLRelationships(entry.getClassAxiomRelationships());
} else {
member.setClassOWLRelationships(entry.getClassAxiomRelationships());
}
} else if (!CompareUtils.isEmpty(entry.getGciAxiomRelationships())) {
member.setGciOWLRelationships(entry.getGciAxiomRelationships());
}
}
setReferencedComponent(member, entry.getReferencedComponentId(), entry.getReferencedComponentType());
return member;
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class SnomedReferenceSetMemberConverter method expandComponentCategory.
private void expandComponentCategory(Options expandOptions, Multimap<String, SnomedReferenceSetMember> referencedComponentIdToMemberMap, Multimap<ComponentCategory, String> componentCategoryToIdMap, ComponentCategory category) {
final Collection<String> componentIds = componentCategoryToIdMap.get(category);
final SearchResourceRequestBuilder<?, BranchContext, ? extends CollectionResource<? extends SnomedCoreComponent>> search;
switch(category) {
case CONCEPT:
search = SnomedRequests.prepareSearchConcept();
break;
case DESCRIPTION:
search = SnomedRequests.prepareSearchDescription();
break;
case RELATIONSHIP:
search = SnomedRequests.prepareSearchRelationship();
break;
default:
throw new UnsupportedOperationException("Category is not supported in referenced component expansion");
}
search.filterByIds(componentIds).setLimit(componentIds.size()).setLocales(locales()).setExpand(expandOptions.get("expand", Options.class));
CollectionResource<? extends SnomedCoreComponent> components = search.build().execute(context());
for (SnomedCoreComponent component : components) {
for (SnomedReferenceSetMember member : referencedComponentIdToMemberMap.get(component.getId())) {
((SnomedReferenceSetMember) member).setReferencedComponent(component);
}
}
}
Aggregations