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

Class Query

src/licensedcode/query.py:155–652  ·  view source on GitHub ↗

A query represent a whole file or string being scanned for licenses. It holds known tokens, known token line positions, unknown tokens positions, and query runs. It also tracks which parts have been matched as matching progresses. For positions, we track primarily the absolute

Source from the content-addressed store, hash-verified

153
154
155class Query(object):
156 """
157 A query represent a whole file or string being scanned for licenses. It
158 holds known tokens, known token line positions, unknown tokens positions,
159 and query runs. It also tracks which parts have been matched as matching
160 progresses.
161
162 For positions, we track primarily the absolute position of known tokens.
163 Unknown tokens are tracked only as the number of unknown in reference to a
164 known token position. (using -1 for unknown tokens that precede the first
165 known token.)
166
167 Line positions (e.g. line numbers) start at 1 with a possibility
168 to set the start_line to another value for special cases.
169
170 A query is broken down in one or more "runs" that are slices of tokens used
171 as a matching unit.
172 """
173
174 __slots__ = (
175 'location',
176 'query_string',
177 'idx',
178 'line_threshold',
179 'tokens',
180 'line_by_pos',
181 'unknowns_by_pos',
182 'unknowns_span',
183 'stopwords_by_pos',
184 'shorts_and_digits_pos',
185 'query_runs',
186 '_whole_query_run',
187 'high_matchables',
188 'low_matchables',
189 'spdx_lid_token_ids',
190 'spdx_lines',
191 'has_long_lines',
192 'is_binary',
193 'start_line',
194 )
195
196 def __init__(
197 self,
198 location=None,
199 query_string=None,
200 idx=None,
201 line_threshold=LINES_THRESHOLD,
202 start_line=1,
203 _test_mode=False,
204 ):
205 """
206 Initialize the query from a file `location` or `query_string` string for
207 an `idx` LicenseIndex.
208 Break query in runs when there are at least `line_threshold` empty lines
209 or junk-only lines.
210 Line numbers start at ``start_line`` which is 1-based by default.
211 """
212 assert (location or query_string) and idx

Calls

no outgoing calls