Search in sources :

Example 56 with LongSet

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

the class LongOpenHashSetTest method create_one_fill_factor.

@Test
public void create_one_fill_factor() {
    LongSet longSet = PrimitiveSets.newLongOpenHashSetWithExpectedSize(10, 1.0d);
    assertTrue("Long set should be empty.", longSet.isEmpty());
}
Also used : LongSet(com.b2international.collections.longs.LongSet) Test(org.junit.Test)

Example 57 with LongSet

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

the class IconIdUpdater method getParentIcon.

private Optional<String> getParentIcon(String id, TaxonomyGraph taxonomyGraph) {
    if (id == null || !taxonomyGraph.containsNode(Long.parseLong(id))) {
        return Optional.empty();
    }
    final Set<String> visitedNodes = Sets.newHashSet();
    final Set<String> candidates = Sets.newTreeSet();
    final Deque<String> toVisit = new ArrayDeque<>();
    toVisit.add(id);
    while (!toVisit.isEmpty()) {
        final String currentId = toVisit.removeFirst();
        if (!visitedNodes.add(currentId)) {
            continue;
        }
        if (availableImages.contains(currentId)) {
            candidates.add(currentId);
        } else {
            // XXX: we stop looking further "up" this hierarchy if there is any image present for the visited concept
            final LongSet ancestorNodeIds = taxonomyGraph.getAncestorNodeIds(Long.parseLong(currentId));
            toVisit.addAll(LongSets.toStringList(ancestorNodeIds));
        }
    }
    return candidates.stream().findFirst();
}
Also used : LongSet(com.b2international.collections.longs.LongSet) ArrayDeque(java.util.ArrayDeque)

Example 58 with LongSet

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

the class InternalSctIdMultimap method get.

@Override
public LongSet get(final long key) {
    final int internalId = internalIdMap.getInternalId(key);
    if (internalId == InternalIdMap.NO_INTERNAL_ID) {
        return PrimitiveSets.newLongOpenHashSet();
    }
    final IntSet values = internalIdMultimap.get(internalId);
    if (values == null) {
        return PrimitiveSets.newLongOpenHashSet();
    } else {
        final LongSet sctIdValues = PrimitiveSets.newLongOpenHashSetWithExpectedSize(values.size());
        for (final IntIterator itr = values.iterator(); itr.hasNext(); ) /*empty*/
        {
            final int valueInternalId = itr.next();
            final long valueSctId = internalIdMap.getSctId(valueInternalId);
            sctIdValues.add(valueSctId);
        }
        return sctIdValues;
    }
}
Also used : IntIterator(com.b2international.collections.ints.IntIterator) IntSet(com.b2international.collections.ints.IntSet) LongSet(com.b2international.collections.longs.LongSet)

Example 59 with LongSet

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

the class InternalSctIdMultimap method keySet.

@Override
public LongSet keySet() {
    final LongSet keySet = PrimitiveSets.newLongOpenHashSetWithExpectedSize(internalIdMultimap.size());
    for (final IntIterator itr = internalIdMultimap.keySet().iterator(); itr.hasNext(); ) /*empty*/
    {
        final int keyInternalId = itr.next();
        final long keySctId = internalIdMap.getSctId(keyInternalId);
        keySet.add(keySctId);
    }
    return keySet;
}
Also used : IntIterator(com.b2international.collections.ints.IntIterator) LongSet(com.b2international.collections.longs.LongSet)

Example 60 with LongSet

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

the class ReasonerTaxonomyInferrer method processNode.

private NodeSet<OWLClass> processNode(final Node<OWLClass> node, Set<Node<OWLClass>> deferredNodes) {
    // Stop the walk if the node has already been visited
    if (isNodeProcessed(node)) {
        return EMPTY_NODE_SET;
    }
    // Check first if the current node is the "bottom" one, as all OWL classes are superclasses of owl:Nothing
    final LongSet conceptIds = collectConceptIds(node, PrimitiveSets.newLongOpenHashSet());
    // Stop the walk if we are at the bottom (we should only reach the bottom node once)
    if (node.isBottomNode()) {
        addUnsatisfiableConcepts(conceptIds);
        processedConceptIds.addAll(conceptIds);
        iterationOrder.addAll(conceptIds);
        return EMPTY_NODE_SET;
    }
    // All parents must be visited before this item can be processed; if not, the same node will appear later again, so stop walking
    final NodeSet<OWLClass> parentNodeSet = reasoner.getSuperClasses(node.getRepresentativeElement(), true);
    for (final Node<OWLClass> parentNode : parentNodeSet) {
        if (!isNodeProcessed(parentNode)) {
            deferredNodes.add(node);
            return EMPTY_NODE_SET;
        }
    }
    // Nodes that contain more than one concept are an indication of equivalence
    if (conceptIds.size() > 1) {
        addEquivalentConcepts(conceptIds);
    }
    // Extract parents and ancestors using the reasoner
    final LongSet parentConceptIds = PrimitiveSets.newLongOpenHashSet();
    for (final Node<OWLClass> parentNode : parentNodeSet) {
        collectConceptIds(parentNode, parentConceptIds);
    }
    addEdges(conceptIds, parentConceptIds);
    processedConceptIds.addAll(conceptIds);
    iterationOrder.addAll(conceptIds);
    return computeNextNodeSet(node);
}
Also used : LongSet(com.b2international.collections.longs.LongSet) OWLClass(org.semanticweb.owlapi.model.OWLClass)

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