Newer
Older
class OrderBasedSuppressor(Suppressor):
def __init__(self) -> None:
super().__init__()
def suppress(self, annotations: List[Tuple[int, int, Any]]) -> List[Tuple[int, int, Any]]:
return suppress_order_based(annotations)
def suppress_order_based(annotations: List[Tuple[int, int, Any]]) -> List[Tuple[int, int, Any]]:
"""If two annotations overlap, the first one int the list is kept.
Args:
annotations (List[Tuple[int, int, Any]]): List of annotations.
List[Tuple[int, int, Any]]: List of annotations with overlapping
if len(annotations) == 0:
return annotations
annotations = annotations
bitarray_size = max([end for _, end, _ in annotations])
bitarray_ = bitarray(bitarray_size)
bitarray_.setall(False)
result = []
for start, end, entity_type in annotations:
if not bitarray_[start:end].any():
bitarray_[start:end] = True
result.append((start, end, entity_type))
return result