Return a tuple of (matches, discarded) sequences of LicenseMatch given `matches` and `discarded` sequences of LicenseMatch. Reintegrate as matches these that may have been filtered too agressively.
(matches, discarded)
| 1524 | |
| 1525 | |
| 1526 | def restore_non_overlapping(matches, discarded): |
| 1527 | """ |
| 1528 | Return a tuple of (matches, discarded) sequences of LicenseMatch given |
| 1529 | `matches` and `discarded` sequences of LicenseMatch. Reintegrate as matches |
| 1530 | these that may have been filtered too agressively. |
| 1531 | """ |
| 1532 | all_matched_qspans = Span().union(*(m.qspan for m in matches)) |
| 1533 | |
| 1534 | to_keep = [] |
| 1535 | to_keep_append = to_keep.append |
| 1536 | |
| 1537 | to_discard = [] |
| 1538 | to_discard_append = to_discard.append |
| 1539 | |
| 1540 | for disc in merge_matches(discarded): |
| 1541 | if not disc.qspan & all_matched_qspans: |
| 1542 | # keep previously discarded matches that do not intersect at all |
| 1543 | to_keep_append(disc) |
| 1544 | disc.discard_reason = DiscardReason.NOT_DISCARDED |
| 1545 | else: |
| 1546 | to_discard_append(disc) |
| 1547 | |
| 1548 | return to_keep, to_discard |
| 1549 | |
| 1550 | |
| 1551 | def filter_below_rule_minimum_coverage( |