Spaces:
Sleeping
Sleeping
File size: 869 Bytes
73376a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | def filter_overlapping_entities(entities):
filtered_entities = []
for entity in entities:
overlap = False
for other_entity in entities:
if entity != other_entity:
if (entity.start >= other_entity.start and entity.start < other_entity.end) or \
(other_entity.start >= entity.start and other_entity.start < entity.end):
overlap = True
if entity.score > other_entity.score:
if entity not in filtered_entities:
filtered_entities.append(entity)
else:
if other_entity not in filtered_entities:
filtered_entities.append(other_entity)
if not overlap:
filtered_entities.append(entity)
return filtered_entities |