A query run is a slice of query tokens identified by a start and end positions inclusive.
| 718 | |
| 719 | |
| 720 | class QueryRun(object): |
| 721 | """ |
| 722 | A query run is a slice of query tokens identified by a start and end |
| 723 | positions inclusive. |
| 724 | """ |
| 725 | __slots__ = ( |
| 726 | 'query', |
| 727 | 'start', |
| 728 | 'end', |
| 729 | 'len_legalese', |
| 730 | 'digit_only_tids', |
| 731 | '_low_matchables', |
| 732 | '_high_matchables', |
| 733 | ) |
| 734 | |
| 735 | def __init__(self, query, start, end=None): |
| 736 | """ |
| 737 | Initialize a query run from starting at `start` and ending at `end` from |
| 738 | a parent `query`. |
| 739 | """ |
| 740 | self.query = query |
| 741 | |
| 742 | # absolute start and end positions of this run in the query |
| 743 | self.start = start |
| 744 | self.end = end |
| 745 | |
| 746 | self.len_legalese = self.query.idx.len_legalese |
| 747 | self.digit_only_tids = self.query.idx.digit_only_tids |
| 748 | self._low_matchables = None |
| 749 | self._high_matchables = None |
| 750 | |
| 751 | def __len__(self): |
| 752 | if self.end is None: |
| 753 | return 0 |
| 754 | return self.end - self.start + 1 |
| 755 | |
| 756 | def __repr__(self, trace_repr=TRACE_REPR): |
| 757 | toks = '' |
| 758 | if trace_repr: |
| 759 | toks = ', tokens="{tokens}"' |
| 760 | base = ( |
| 761 | 'QueryRun(' |
| 762 | 'start={start}, ' |
| 763 | 'len={length}, ' |
| 764 | 'start_line={start_line}, ' |
| 765 | 'end_line={end_line}' |
| 766 | f'{toks})' |
| 767 | ) |
| 768 | qdata = self.to_dict(brief=False, comprehensive=True, include_high=False) |
| 769 | return base.format(**qdata) |
| 770 | |
| 771 | @property |
| 772 | def start_line(self): |
| 773 | return self.query.line_by_pos[self.start] |
| 774 | |
| 775 | @property |
| 776 | def end_line(self): |
| 777 | return self.query.line_by_pos[self.end] |
no outgoing calls
no test coverage detected