Return a new match object combining self and an other match.
(self, other)
| 636 | return self.qspan.is_after(other.qspan) and self.ispan.is_after(other.ispan) |
| 637 | |
| 638 | def combine(self, other): |
| 639 | """ |
| 640 | Return a new match object combining self and an other match. |
| 641 | """ |
| 642 | if self.rule != other.rule: |
| 643 | raise TypeError( |
| 644 | 'Cannot combine matches with different rules: ' |
| 645 | f'from: {self!r}, to: {other!r}' |
| 646 | ) |
| 647 | |
| 648 | if other.matcher not in self.matcher: |
| 649 | newmatcher = ' '.join([self.matcher, other.matcher]) |
| 650 | newmatcher_order = max([self.matcher_order, other.matcher_order]) |
| 651 | else: |
| 652 | newmatcher = self.matcher |
| 653 | newmatcher_order = self.matcher_order |
| 654 | |
| 655 | if ( |
| 656 | self.discard_reason == DiscardReason.NOT_DISCARDED |
| 657 | or other.discard_reason == DiscardReason.NOT_DISCARDED |
| 658 | ): |
| 659 | discard_reason = DiscardReason.NOT_DISCARDED |
| 660 | |
| 661 | elif ( |
| 662 | self.discard_reason == DiscardReason.MISSING_REQUIRED_PHRASES |
| 663 | and other.discard_reason == DiscardReason.MISSING_REQUIRED_PHRASES |
| 664 | ): |
| 665 | discard_reason = DiscardReason.MISSING_REQUIRED_PHRASES |
| 666 | |
| 667 | elif self.discard_reason == DiscardReason.MISSING_REQUIRED_PHRASES: |
| 668 | discard_reason = other.discard_reason |
| 669 | |
| 670 | elif other.discard_reason == DiscardReason.MISSING_REQUIRED_PHRASES: |
| 671 | discard_reason = self.discard_reason |
| 672 | |
| 673 | else: |
| 674 | discard_reason = self.discard_reason |
| 675 | |
| 676 | combined = LicenseMatch( |
| 677 | rule=self.rule, |
| 678 | qspan=Span(self.qspan | other.qspan), |
| 679 | ispan=Span(self.ispan | other.ispan), |
| 680 | hispan=Span(self.hispan | other.hispan), |
| 681 | query_run_start=min(self.query_run_start, other.query_run_start), |
| 682 | matcher=newmatcher, |
| 683 | matcher_order=newmatcher_order, |
| 684 | query=self.query, |
| 685 | discard_reason=discard_reason, |
| 686 | ) |
| 687 | return combined |
| 688 | |
| 689 | def update(self, other): |
| 690 | """ |