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);
}
}
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 $;
}
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();
}
Aggregations