MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / QueryRun

Class QueryRun

src/licensedcode/query.py:720–913  ·  view source on GitHub ↗

A query run is a slice of query tokens identified by a start and end positions inclusive.

Source from the content-addressed store, hash-verified

718
719
720class 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]

Callers 4

whole_query_runMethod · 0.85
break_on_boundariesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected