Search in sources :

Example 16 with LongIterator

use of com.b2international.collections.longs.LongIterator in project snow-owl by b2ihealthcare.

the class ClassificationTracker method indexEquivalentConcepts.

private void indexEquivalentConcepts(final Writer writer, final String classificationId, final IInternalSctIdMultimap equivalentConcepts) throws IOException {
    for (final LongIterator itr = equivalentConcepts.keySet().iterator(); itr.hasNext(); ) /*empty*/
    {
        final long representativeConcept = itr.next();
        final LongSet equivalents = equivalentConcepts.get(representativeConcept);
        final LongList orderedConcepts = PrimitiveLists.newLongArrayListWithExpectedSize(equivalents.size() + 1);
        orderedConcepts.add(representativeConcept);
        orderedConcepts.addAll(equivalents);
        final EquivalentConceptSetDocument equivalentDoc = EquivalentConceptSetDocument.builder().classificationId(classificationId).conceptIds(orderedConcepts).unsatisfiable(false).build();
        writer.put(equivalentDoc);
    }
}
Also used : EquivalentConceptSetDocument(com.b2international.snowowl.snomed.reasoner.index.EquivalentConceptSetDocument) LongSet(com.b2international.collections.longs.LongSet) LongList(com.b2international.collections.longs.LongList) LongIterator(com.b2international.collections.longs.LongIterator)

Example 17 with LongIterator

use of com.b2international.collections.longs.LongIterator in project snow-owl by b2ihealthcare.

the class Rf2GlobalValidator method validateTerminologyComponents.

public void validateTerminologyComponents(final List<Rf2EffectiveTimeSlice> slices, final ImportDefectAcceptor globalDefectAcceptor, final BranchContext context) {
    dependenciesByEffectiveTime = Maps.newHashMap();
    skippableMemberDependenciesByEffectiveTime = Maps.newHashMap();
    // Check the slices in reverse order for missing dependencies
    for (Rf2EffectiveTimeSlice slice : Lists.reverse(slices)) {
        final String effectiveTimeLabel = Rf2EffectiveTimeSlice.SNAPSHOT_SLICE.equals(slice.getEffectiveTime()) ? "..." : String.format(" in effective time '%s'", slice.getEffectiveTime());
        log.info("Validating component consistency{}", effectiveTimeLabel);
        // Resolve pending dependencies with the current slice content
        final Set<String> contentInSlice = Set.copyOf(slice.getContent().keySet());
        dependenciesByEffectiveTime.keySet().removeAll(contentInSlice);
        // Core component dependencies
        for (final LongSet componentDependencies : slice.getDependenciesByComponent().values()) {
            final LongIterator it = componentDependencies.iterator();
            while (it.hasNext()) {
                final long dependencyId = it.next();
                final String stringDependencyId = Long.toString(dependencyId);
                // Insert or update any entry with the current slice key, unless the current slice has the component
                if (!contentInSlice.contains(stringDependencyId)) {
                    dependenciesByEffectiveTime.put(stringDependencyId, slice.getEffectiveTime());
                }
            }
        }
        // Dependencies of reference set members includes the reference component ID, check them separately
        final LongIterator referencedComponentIds = slice.getMembersByReferencedComponent().keySet().iterator();
        while (referencedComponentIds.hasNext()) {
            final long referencedComponentId = referencedComponentIds.next();
            final String stringReferencedComponentId = Long.toString(referencedComponentId);
            if (!contentInSlice.contains(stringReferencedComponentId)) {
                Set<String> referringMembers = slice.getMembersByReferencedComponent().get(referencedComponentId);
                boolean failOnMissingReferences = false;
                for (String memberId : referringMembers) {
                    String[] referringMember = slice.getContent().get(memberId);
                    String referenceSet = referringMember[5];
                    failOnMissingReferences = !ignoreMissingReferencesIn.contains(referenceSet);
                }
                if (failOnMissingReferences) {
                    dependenciesByEffectiveTime.put(stringReferencedComponentId, slice.getEffectiveTime());
                } else {
                    skippableMemberDependenciesByEffectiveTime.put(stringReferencedComponentId, slice.getEffectiveTime());
                }
            }
        }
        // Validate reference set type in similar reference sets
        validateType(slice, globalDefectAcceptor);
    }
    final Set<String> missingConceptIds = newHashSet();
    final Set<String> missingDescriptionIds = newHashSet();
    final Set<String> missingRelationshipIds = newHashSet();
    // Anything that remains is not resolved by the imported data; check if it is in Snow Owl
    if (!dependenciesByEffectiveTime.isEmpty()) {
        Set<String> conceptIds = newHashSet();
        Set<String> descriptionIds = newHashSet();
        Set<String> relationshipIds = newHashSet();
        dependenciesByEffectiveTime.keySet().stream().forEach(id -> {
            switch(SnomedIdentifiers.getComponentCategory(id)) {
                case CONCEPT:
                    conceptIds.add(id);
                    break;
                case DESCRIPTION:
                    descriptionIds.add(id);
                    break;
                case RELATIONSHIP:
                    relationshipIds.add(id);
                    break;
                default:
                    log.error("Unknown component type for identifier: {}", id);
                    break;
            }
        });
        skippableMemberDependenciesByEffectiveTime.keySet().stream().forEach(id -> {
            switch(SnomedIdentifiers.getComponentCategory(id)) {
                case CONCEPT:
                    conceptIds.add(id);
                    break;
                case DESCRIPTION:
                    descriptionIds.add(id);
                    break;
                case RELATIONSHIP:
                    relationshipIds.add(id);
                    break;
                default:
                    log.error("Unknown component type for identifier: {}", id);
                    break;
            }
        });
        log.trace("Fetch existing concept IDs...");
        missingConceptIds.addAll(fetchComponentIds(context, conceptIds, SnomedConceptDocument.class));
        if (!missingConceptIds.isEmpty()) {
            missingConceptIds.forEach(id -> {
                reportMissingComponent(globalDefectAcceptor, id, dependenciesByEffectiveTime.get(id), "concept", canBeSkipped(id));
            });
        }
        log.trace("Fetch existing description IDs...");
        missingDescriptionIds.addAll(fetchComponentIds(context, descriptionIds, SnomedDescriptionIndexEntry.class));
        if (!missingDescriptionIds.isEmpty()) {
            missingDescriptionIds.forEach(id -> {
                reportMissingComponent(globalDefectAcceptor, id, dependenciesByEffectiveTime.get(id), "description", canBeSkipped(id));
            });
        }
        log.trace("Fetch existing relationship IDs...");
        missingRelationshipIds.addAll(fetchComponentIds(context, relationshipIds, SnomedRelationshipIndexEntry.class));
        if (!missingRelationshipIds.isEmpty()) {
            missingRelationshipIds.forEach(id -> {
                reportMissingComponent(globalDefectAcceptor, id, dependenciesByEffectiveTime.get(id), "relationship", canBeSkipped(id));
            });
        }
    }
    removeSkippableMembers(slices);
    skippableMemberDependenciesByEffectiveTime.clear();
    dependenciesByEffectiveTime.clear();
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Rf2EffectiveTimeSlice(com.b2international.snowowl.snomed.datastore.request.rf2.importer.Rf2EffectiveTimeSlice) LongSet(com.b2international.collections.longs.LongSet) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) LongIterator(com.b2international.collections.longs.LongIterator)

Aggregations

LongIterator (com.b2international.collections.longs.LongIterator)17 LongSet (com.b2international.collections.longs.LongSet)9 LongList (com.b2international.collections.longs.LongList)5 Test (org.junit.Test)5 PrimitiveMaps (com.b2international.collections.PrimitiveMaps)2 PrimitiveSets (com.b2international.collections.PrimitiveSets)2 AbstractLongIterator (com.b2international.collections.longs.AbstractLongIterator)2 LongCollection (com.b2international.collections.longs.LongCollection)2 LongKeyMap (com.b2international.collections.longs.LongKeyMap)2 LongSets (com.b2international.commons.collect.LongSets)2 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)2 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)2 ConcreteDomainFragment (com.b2international.snowowl.snomed.datastore.ConcreteDomainFragment)2 StatementFragment (com.b2international.snowowl.snomed.datastore.StatementFragment)2 StatementFragmentWithDestination (com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination)2 StatementFragmentWithValue (com.b2international.snowowl.snomed.datastore.StatementFragmentWithValue)2 PropertyChain (com.b2international.snowowl.snomed.datastore.index.taxonomy.PropertyChain)2 ReasonerTaxonomy (com.b2international.snowowl.snomed.datastore.index.taxonomy.ReasonerTaxonomy)2 INormalFormGenerator (com.b2international.snowowl.snomed.reasoner.classification.INormalFormGenerator)2 ReasonerTaxonomyInferrer (com.b2international.snowowl.snomed.reasoner.classification.ReasonerTaxonomyInferrer)2