Initialize the index with an iterable of Rule objects. ``_legalese`` is a sorted mapping of common license-specific words aka. legalese as {token: id} ``_spdx_tokens`` is a set of tokens used in SPDX license identifiers ``_license_tokens`` is a set of "license" token
(
self,
rules=None,
_legalese=common_license_words,
_spdx_tokens=frozenset(),
_license_tokens=frozenset(),
_all_languages=False,
)
| 165 | ) |
| 166 | |
| 167 | def __init__( |
| 168 | self, |
| 169 | rules=None, |
| 170 | _legalese=common_license_words, |
| 171 | _spdx_tokens=frozenset(), |
| 172 | _license_tokens=frozenset(), |
| 173 | _all_languages=False, |
| 174 | ): |
| 175 | """ |
| 176 | Initialize the index with an iterable of Rule objects. |
| 177 | ``_legalese`` is a sorted mapping of common license-specific words aka. legalese as {token: id} |
| 178 | ``_spdx_tokens`` is a set of tokens used in SPDX license identifiers |
| 179 | ``_license_tokens`` is a set of "license" tokens used as start or end of a rule |
| 180 | If ``_all_languages`` is True, use all spoken languages license and rules. |
| 181 | Otherwise, use only English rules and licenses. |
| 182 | """ |
| 183 | # largest token ID for a "legalese" token. A token with a larger id than |
| 184 | # len_legalese is considered a "junk" very common token |
| 185 | self.len_legalese = 0 |
| 186 | |
| 187 | # mapping of token string > integer token id |
| 188 | self.dictionary = {} |
| 189 | |
| 190 | # set of token ids made entirely of digits |
| 191 | self.digit_only_tids = set() |
| 192 | |
| 193 | # Note: all the following are mappings-like (using lists) of |
| 194 | # rid-> data are lists of data where the index integer is the rule id. |
| 195 | |
| 196 | # mapping of rule int id -> rule objects |
| 197 | # TODO: rename to rules_by_identifier for consistency |
| 198 | self.rules_by_id = {} |
| 199 | |
| 200 | # maping-like of rule int id -> rule objects proper |
| 201 | self.rules_by_rid = [] |
| 202 | |
| 203 | # maping-like of rule int id -> sequence of token int ids |
| 204 | self.tids_by_rid = [] |
| 205 | |
| 206 | # mapping-like of rule id->(mapping of (token_id->[positions, ...]) |
| 207 | # We track only high/good tokens there. This is a "traditional" |
| 208 | # inverted index postings list |
| 209 | self.high_postings_by_rid = [] |
| 210 | |
| 211 | # mapping-like of rule int id -> tokens ids sets/multisets |
| 212 | self.sets_by_rid = [] |
| 213 | self.msets_by_rid = [] |
| 214 | |
| 215 | # mapping of hash -> single int rid for hash match: duplicated rules are not allowed |
| 216 | self.rid_by_hash = {} |
| 217 | |
| 218 | # Aho-Corasick automatons for regular rules and experimental fragments |
| 219 | self.rules_automaton = match_aho.get_automaton() |
| 220 | self.fragments_automaton = USE_AHO_FRAGMENTS and match_aho.get_automaton() |
| 221 | self.starts_automaton = USE_RULE_STARTS and match_aho.get_automaton() |
| 222 | self.unknown_automaton = match_unknown.get_automaton() |
| 223 | |
| 224 | # disjunctive sets of rule ids: regular and false positive |
nothing calls this directly
no test coverage detected