Search in sources :

Example 16 with LongList

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

the class NormalFormGenerator method computeChanges.

@Override
public final void computeChanges(final IProgressMonitor monitor, final OntologyChangeProcessor<StatementFragment> statementProcessor, final OntologyChangeProcessor<ConcreteDomainFragment> concreteDomainProcessor) {
    final Stopwatch stopwatch = Stopwatch.createStarted();
    LOGGER.info(">>> Distribution normal form generation");
    final LongList entries = reasonerTaxonomy.getIterationOrder();
    final SubMonitor subMonitor = SubMonitor.convert(monitor, "Generating distribution normal form...", entries.size() * 2);
    try {
        LongSet previousLayer = null;
        LongSet currentLayer = PrimitiveSets.newLongOpenHashSet();
        final Set<Long> graphTypeIds = reasonerTaxonomy.getPropertyChains().stream().map(PropertyChain::getDestinationType).collect(Collectors.toSet());
        // The first round can be skipped entirely, if no type IDs participate in a property chain
        final boolean propertyChainsPresent = !graphTypeIds.isEmpty();
        if (propertyChainsPresent) {
            // Initialize node graphs for properties we need to traverse
            LOGGER.info("--- Initializing node graphs for types: {}", graphTypeIds);
            graphTypeIds.forEach(id -> transitiveNodeGraphs.put(id, new NodeGraph()));
            // Round 1: build alternative hierarchies
            for (final LongIterator itr = entries.iterator(); itr.hasNext(); ) /* empty */
            {
                final long conceptId = itr.next();
                if (conceptId == ReasonerTaxonomyInferrer.DEPTH_CHANGE) {
                    if (previousLayer != null) {
                        invalidate(previousLayer);
                    }
                    previousLayer = currentLayer;
                    currentLayer = PrimitiveSets.newLongOpenHashSet();
                    continue;
                }
                precomputeProperties(conceptId, false);
                final Collection<StatementFragment> inferredNonIsAFragments = statementCache.get(conceptId);
                inferredNonIsAFragments.stream().filter(r -> transitiveNodeGraphs.keySet().contains(r.getTypeId())).filter(StatementFragmentWithDestination.class::isInstance).map(StatementFragmentWithDestination.class::cast).forEachOrdered(r -> transitiveNodeGraphs.get(r.getTypeId()).addParent(conceptId, r.getDestinationId()));
            }
            // Clear the last layer of concepts
            previousLayer = null;
            currentLayer = PrimitiveSets.newLongOpenHashSet();
            statementCache.clear();
            concreteDomainCache.clear();
        } else {
            LOGGER.info("--- Node graphs computation skipped, no types used for property chaining");
        }
        LOGGER.info("--- Use node graphs for hierarchy computation");
        // Round 2: record changes using the hierarchies
        for (final LongIterator itr = entries.iterator(); itr.hasNext(); ) /* empty */
        {
            final long conceptId = itr.next();
            if (conceptId == ReasonerTaxonomyInferrer.DEPTH_CHANGE) {
                if (previousLayer != null) {
                    invalidate(previousLayer);
                }
                previousLayer = currentLayer;
                currentLayer = PrimitiveSets.newLongOpenHashSet();
                continue;
            }
            // Run costly comparison of property chain hierarchies only if there are any
            precomputeProperties(conceptId, propertyChainsPresent);
            final Collection<StatementFragment> existingStatements = reasonerTaxonomy.getExistingInferredRelationships().get(conceptId);
            final Collection<StatementFragment> targetStatements = getTargetRelationships(conceptId);
            statementProcessor.apply(conceptId, existingStatements, targetStatements, StatementFragmentOrdering.INSTANCE, subMonitor.newChild(1));
            final Collection<ConcreteDomainFragment> existingMembers = reasonerTaxonomy.getInferredConcreteDomainMembers().get(Long.toString(conceptId));
            final Collection<ConcreteDomainFragment> targetMembers = getTargetMembers(conceptId);
            concreteDomainProcessor.apply(conceptId, existingMembers, targetMembers, ConcreteDomainChangeOrdering.INSTANCE, subMonitor.newChild(1));
        }
    } finally {
        subMonitor.done();
        LOGGER.info("<<< Distribution normal form generation [{}]", stopwatch.toString());
    }
}
Also used : LongKeyMap(com.b2international.collections.longs.LongKeyMap) Iterables(com.google.common.collect.Iterables) PrimitiveMaps(com.b2international.collections.PrimitiveMaps) SubMonitor(org.eclipse.core.runtime.SubMonitor) OntologyChangeProcessor(com.b2international.snowowl.snomed.reasoner.diff.OntologyChangeProcessor) Stopwatch(com.google.common.base.Stopwatch) LoggerFactory(org.slf4j.LoggerFactory) StatementFragmentWithDestination(com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination) ConcreteDomainChangeOrdering(com.b2international.snowowl.snomed.reasoner.diff.concretedomain.ConcreteDomainChangeOrdering) Multimap(com.google.common.collect.Multimap) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Multimaps(com.google.common.collect.Multimaps) PrimitiveSets(com.b2international.collections.PrimitiveSets) LongSet(com.b2international.collections.longs.LongSet) ConcreteDomainFragment(com.b2international.snowowl.snomed.datastore.ConcreteDomainFragment) ImmutableList(com.google.common.collect.ImmutableList) LongSets(com.b2international.commons.collect.LongSets) ReasonerTaxonomyInferrer(com.b2international.snowowl.snomed.reasoner.classification.ReasonerTaxonomyInferrer) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Predicates(com.google.common.base.Predicates) PropertyChain(com.b2international.snowowl.snomed.datastore.index.taxonomy.PropertyChain) StatementFragmentOrdering(com.b2international.snowowl.snomed.reasoner.diff.relationship.StatementFragmentOrdering) ReasonerTaxonomy(com.b2international.snowowl.snomed.datastore.index.taxonomy.ReasonerTaxonomy) Logger(org.slf4j.Logger) LongIterator(com.b2international.collections.longs.LongIterator) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) INormalFormGenerator(com.b2international.snowowl.snomed.reasoner.classification.INormalFormGenerator) Collection(java.util.Collection) Set(java.util.Set) StatementFragmentWithValue(com.b2international.snowowl.snomed.datastore.StatementFragmentWithValue) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LongList(com.b2international.collections.longs.LongList) List(java.util.List) StatementFragment(com.b2international.snowowl.snomed.datastore.StatementFragment) LongSet(com.b2international.collections.longs.LongSet) Stopwatch(com.google.common.base.Stopwatch) SubMonitor(org.eclipse.core.runtime.SubMonitor) LongList(com.b2international.collections.longs.LongList) StatementFragment(com.b2international.snowowl.snomed.datastore.StatementFragment) ConcreteDomainFragment(com.b2international.snowowl.snomed.datastore.ConcreteDomainFragment) StatementFragmentWithDestination(com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination) LongIterator(com.b2international.collections.longs.LongIterator)

Example 17 with LongList

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

the class ReasonerTaxonomyBuilder method addNeverGroupedTypeIds.

public ReasonerTaxonomyBuilder addNeverGroupedTypeIds(final RevisionSearcher searcher) {
    entering("Registering 'never grouped' type IDs using revision searcher");
    final ExpressionBuilder whereExpressionBuilder = Expressions.builder().filter(SnomedRefSetMemberIndexEntry.Expressions.active()).filter(SnomedRefSetMemberIndexEntry.Expressions.refsetId(Concepts.REFSET_MRCM_ATTRIBUTE_DOMAIN_INTERNATIONAL)).filter(SnomedRefSetMemberIndexEntry.Expressions.mrcmGrouped(false));
    if (!excludedModuleIds.isEmpty()) {
        whereExpressionBuilder.mustNot(modules(excludedModuleIds));
    }
    final LongList fragments = PrimitiveLists.newLongArrayListWithExpectedSize(SCROLL_LIMIT);
    Query.select(String.class).from(SnomedRefSetMemberIndexEntry.class).fields(SnomedRefSetMemberIndexEntry.Fields.REFERENCED_COMPONENT_ID).where(whereExpressionBuilder.build()).sortBy(SortBy.builder().sortByField(SnomedRefSetMemberIndexEntry.Fields.REFERENCED_COMPONENT_ID, Order.ASC).sortByField(SnomedRefSetMemberIndexEntry.Fields.ID, Order.ASC).build()).limit(SCROLL_LIMIT).build().stream(searcher).forEachOrdered(hits -> {
        for (final String referencedComponentId : hits) {
            fragments.add(Long.parseLong(referencedComponentId));
        }
        neverGroupedTypeIds.addAll(fragments);
        fragments.clear();
    });
    leaving("Registering 'never grouped' type IDs using revision searcher");
    return this;
}
Also used : LongList(com.b2international.collections.longs.LongList) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder)

Example 18 with LongList

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

the class EmptyLongListTest method containsAll_non_empty.

@Test
public void containsAll_non_empty() {
    LongList emptyList = LongCollections.emptyList();
    LongList otherList = PrimitiveLists.newLongArrayList(5L, 10L);
    assertFalse("Empty list should not contain all elements from second list.", emptyList.containsAll(otherList));
    assertTrue("Second list should not contain all elements from empty list.", otherList.containsAll(emptyList));
}
Also used : LongList(com.b2international.collections.longs.LongList) Test(org.junit.Test)

Example 19 with LongList

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

the class EmptyLongListTest method retainAll_opposite.

@Test
public void retainAll_opposite() {
    LongList emptyList = LongCollections.emptyList();
    LongList otherList = PrimitiveLists.newLongArrayList(0L, 5L, 10L);
    otherList.retainAll(emptyList);
    assertEquals("Empty list should remain empty.", 0, emptyList.size());
    assertEquals("Non-empty list should become empty.", 0, emptyList.size());
}
Also used : LongList(com.b2international.collections.longs.LongList) Test(org.junit.Test)

Example 20 with LongList

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

the class EmptyLongListTest method containsAll_null.

@Test(expected = NullPointerException.class)
public void containsAll_null() {
    LongList emptyList = LongCollections.emptyList();
    emptyList.containsAll(null);
}
Also used : LongList(com.b2international.collections.longs.LongList) Test(org.junit.Test)

Aggregations

LongList (com.b2international.collections.longs.LongList)26 Test (org.junit.Test)22 LongIterator (com.b2international.collections.longs.LongIterator)4 LongSet (com.b2international.collections.longs.LongSet)2 PrimitiveMaps (com.b2international.collections.PrimitiveMaps)1 PrimitiveSets (com.b2international.collections.PrimitiveSets)1 LongKeyMap (com.b2international.collections.longs.LongKeyMap)1 LongSets (com.b2international.commons.collect.LongSets)1 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)1 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)1 ConcreteDomainFragment (com.b2international.snowowl.snomed.datastore.ConcreteDomainFragment)1 StatementFragment (com.b2international.snowowl.snomed.datastore.StatementFragment)1 StatementFragmentWithDestination (com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination)1 StatementFragmentWithValue (com.b2international.snowowl.snomed.datastore.StatementFragmentWithValue)1 PropertyChain (com.b2international.snowowl.snomed.datastore.index.taxonomy.PropertyChain)1 ReasonerTaxonomy (com.b2international.snowowl.snomed.datastore.index.taxonomy.ReasonerTaxonomy)1 INormalFormGenerator (com.b2international.snowowl.snomed.reasoner.classification.INormalFormGenerator)1 ReasonerTaxonomyInferrer (com.b2international.snowowl.snomed.reasoner.classification.ReasonerTaxonomyInferrer)1 OntologyChangeProcessor (com.b2international.snowowl.snomed.reasoner.diff.OntologyChangeProcessor)1