Search in sources :

Example 61 with LongSet

use of com.b2international.collections.longs.LongSet 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 62 with LongSet

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

the class TaxonomyGraph method processElements.

private LongSet processElements(final long conceptId, final int... internalIds) {
    if (CompareUtils.isEmpty(internalIds)) {
        return PrimitiveSets.newLongOpenHashSet();
    }
    final LongSet $ = PrimitiveSets.newLongOpenHashSetWithExpectedSize(internalIds.length);
    for (final int i : internalIds) {
        long convertedId = getNodeId(i);
        if (conceptId == convertedId && checkCycles) {
            throw new CycleDetectedException("Concept " + conceptId + " would introduce a cycle in the ISA graph (loop).");
        }
        $.add(convertedId);
    }
    return $;
}
Also used : LongSet(com.b2international.collections.longs.LongSet) CycleDetectedException(com.b2international.commons.exceptions.CycleDetectedException)

Example 63 with LongSet

use of com.b2international.collections.longs.LongSet 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

LongSet (com.b2international.collections.longs.LongSet)63 Test (org.junit.Test)46 LongIterator (com.b2international.collections.longs.LongIterator)9 PrimitiveSets (com.b2international.collections.PrimitiveSets)3 LongList (com.b2international.collections.longs.LongList)3 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)3 ImmutableList (com.google.common.collect.ImmutableList)3 Sets (com.google.common.collect.Sets)3 Collection (java.util.Collection)3 PrimitiveMaps (com.b2international.collections.PrimitiveMaps)2 IntIterator (com.b2international.collections.ints.IntIterator)2 LongKeyMap (com.b2international.collections.longs.LongKeyMap)2 LongSets (com.b2international.commons.collect.LongSets)2 CycleDetectedException (com.b2international.commons.exceptions.CycleDetectedException)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 List (java.util.List)2