Initialize the query from a file `location` or `query_string` string for an `idx` LicenseIndex. Break query in runs when there are at least `line_threshold` empty lines or junk-only lines. Line numbers start at ``start_line`` which is 1-based by default.
(
self,
location=None,
query_string=None,
idx=None,
line_threshold=LINES_THRESHOLD,
start_line=1,
_test_mode=False,
)
| 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 |
| 213 | |
| 214 | self.location = location |
| 215 | self.query_string = query_string |
| 216 | self.idx = idx |
| 217 | |
| 218 | self.line_threshold = line_threshold |
| 219 | self.start_line = start_line |
| 220 | |
| 221 | # True if the text is made of very long lines |
| 222 | self.has_long_lines = False |
| 223 | |
| 224 | # True if the query is binary |
| 225 | self.is_binary = False |
| 226 | |
| 227 | # known token ids array |
| 228 | self.tokens = [] |
| 229 | |
| 230 | # index of known position -> line number where the pos is the list index |
| 231 | self.line_by_pos = [] |
| 232 | |
| 233 | # index of "known positions" (yes really!) to a number of unknown tokens |
| 234 | # after that known position. For unknowns at the start, the position is |
| 235 | # using the magic -1 key |
| 236 | self.unknowns_by_pos = {} |
| 237 | |
| 238 | # Span of "known positions" (yes really!) followed by unknown token(s) |
| 239 | self.unknowns_span = None |
| 240 | |
| 241 | # index of "known positions" (yes really!) to a number of stopword |
| 242 | # tokens after this known position. For stopwords at the start, the |
| 243 | # position is using the magic -1 key |
| 244 | self.stopwords_by_pos = {} |
| 245 | |
| 246 | # set of known positions were there is a short, single letter token or |
| 247 | # digits-only token |
| 248 | # TODO: consider using an intbitset |
| 249 | self.shorts_and_digits_pos = set() |
| 250 | |
| 251 | # list of the three SPDX-License-Identifier tokens to identify to detect |
| 252 | # a line for SPDX id matching. |
| 253 | # note: this will not match anything if the index is not properly set |
nothing calls this directly
no test coverage detected