I'm working on an NLP project and I have a list with character spans in some text. This list could look like the following:
[(1,4),(1,7),(4,9),(8,15)]
So my task is to return all non-overlapping pairs.
If two or more number pairs are overlapping, then the pair with the longest span should be returned. In my example, I want to return [(1,7),(8,15)]
. How can I do this?
EDIT
I don't want to merge my intervals like in Merge overlap here. But i wan't to return all pairs/intervals/tuples except if the values in some tuples overlaps. e.g. (1,4) and (1,7) overlaps, (4,9) overlaps with (1,4) and (1,7) . If there is some overlap i want to return the tuple with the largest span e.g. (1,7) = span 7, (1,4) = span 4, (4,9) = span 5. That means that it should return (1,7) and (8,15) as well since (8,15) are not overlapping (1,7)