use of com.b2international.collections.longs.LongKeyMap in project snow-owl by b2ihealthcare.
the class NormalFormGenerator method precomputeProperties.
private void precomputeProperties(final long conceptId, final boolean useNodeGraphs) {
final LongSet parentIds = reasonerTaxonomy.getInferredAncestors().getDestinations(conceptId, true);
/*
* Non IS-A relationships are fetched from ancestors; redundancy must be removed. Since we are working through the list
* of concepts in breadth-first order, we only need to look at cached results from the direct parents, and "distill"
* a non-redundant set of components out of them.
*/
final LongKeyMap<Collection<StatementFragment>> candidateNonIsARelationships = PrimitiveMaps.newLongKeyOpenHashMap();
for (final LongIterator itr = parentIds.iterator(); itr.hasNext(); ) /* empty */
{
final long parentId = itr.next();
candidateNonIsARelationships.put(parentId, statementCache.get(parentId));
}
// Stated axiom fragments are non-IS A, but any stated relationships need to be filtered (if they are still present)
final Collection<StatementFragment> ownStatedRelationships = reasonerTaxonomy.getStatedRelationships().get(conceptId);
final Collection<StatementFragment> ownStatedNonIsaRelationships = ownStatedRelationships.stream().filter(r -> r.getTypeId() != IS_A).collect(Collectors.toList());
candidateNonIsARelationships.put(conceptId, ImmutableList.<StatementFragment>builder().addAll(ownStatedNonIsaRelationships).addAll(reasonerTaxonomy.getAxiomNonIsARelationships().get(conceptId)).addAll(reasonerTaxonomy.getAdditionalGroupedRelationships().get(conceptId)).build());
// Collect existing inferred relationships for cross-referencing group numbers
final Collection<StatementFragment> ownInferredRelationships = reasonerTaxonomy.getExistingInferredRelationships().get(conceptId);
final Collection<StatementFragment> ownInferredNonIsaRelationships = ownInferredRelationships.stream().filter(r -> r.getTypeId() != IS_A).collect(Collectors.toList());
/*
* Do the same as the above, but for CD members
*/
final LongKeyMap<Collection<ConcreteDomainFragment>> candidateMembers = PrimitiveMaps.newLongKeyOpenHashMap();
for (final LongIterator itr = parentIds.iterator(); itr.hasNext(); ) /* empty */
{
final long parentId = itr.next();
candidateMembers.put(parentId, concreteDomainCache.get(parentId));
}
final String referencedComponentId = Long.toString(conceptId);
final Collection<ConcreteDomainFragment> ownStatedMembers = reasonerTaxonomy.getStatedConcreteDomainMembers().get(referencedComponentId);
final Collection<ConcreteDomainFragment> ownAdditionalGroupedMembers = reasonerTaxonomy.getAdditionalGroupedConcreteDomainMembers().get(referencedComponentId);
candidateMembers.put(conceptId, ImmutableList.<ConcreteDomainFragment>builder().addAll(ownStatedMembers).addAll(ownAdditionalGroupedMembers).build());
final Collection<ConcreteDomainFragment> ownInferredMembers = reasonerTaxonomy.getInferredConcreteDomainMembers().get(referencedComponentId);
// Remove redundancy
final NormalFormGroupSet targetGroupSet = getTargetGroupSet(conceptId, parentIds, ownInferredNonIsaRelationships, ownInferredMembers, candidateNonIsARelationships, candidateMembers, useNodeGraphs);
// Extract results; place them in the cache, so following concepts can re-use it
statementCache.put(conceptId, ImmutableList.copyOf(relationshipsFromGroupSet(targetGroupSet)));
concreteDomainCache.put(conceptId, ImmutableList.copyOf(membersFromGroupSet(targetGroupSet)));
}
Aggregations