def _merge_pii_annotation_results()

in src/processors.py [0:0]


    def _merge_pii_annotation_results(self, segment: Document, existing_annotations: List = []):

        if not existing_annotations:
            existing_annotations.extend(segment.pii_entities)
            return

        for pii_entity in segment.pii_entities:
            k = len(existing_annotations) - 1
            while k > 0:
                overlap_result = self._is_overlapping_annotations(existing_annotations[k], pii_entity)
                if overlap_result > 0:
                    existing_annotations.append(pii_entity)
                    break
                elif overlap_result == 0:
                    LOG.debug("Annotation: " + str(existing_annotations[k]) + " conflicts with: " + str(pii_entity))
                    resolved_annotation = self._resolve_overlapped_annotation(existing_annotations[k], pii_entity)
                    LOG.debug("Deleting annotation:" + str(existing_annotations[k]))
                    del existing_annotations[k]
                    for i, annotation in enumerate(resolved_annotation):
                        LOG.debug("Adding annotation:" + str(annotation))
                        existing_annotations.insert(k + i, annotation)
                    break
                else:
                    k -= 1

        return existing_annotations