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

Function get_matched_positions

src/licensedcode/match_aho.py:162–176  ·  view source on GitHub ↗

Yield tuples of matched positions as (rid, qstart, qend, istart, iend) such that these start and end positions are suitable as range() arguments. Match `tokens` sequence of token ids starting at the `qbegin` absolute query start position position using the `automaton`.

(tokens, qbegin, automaton)

Source from the content-addressed store, hash-verified

160
161
162def get_matched_positions(tokens, qbegin, automaton):
163 """
164 Yield tuples of matched positions as (rid, qstart, qend, istart, iend) such
165 that these start and end positions are suitable as range() arguments. Match
166 `tokens` sequence of token ids starting at the `qbegin` absolute query start
167 position position using the `automaton`.
168 """
169 for qend, matched_rule_segments in get_matches(tokens, qbegin, automaton):
170 for rid, istart, iend in matched_rule_segments:
171 if TRACE_DEEP:
172 logger_debug(' #EXACT get_matches: found match to rule:', rid)
173 iend = iend + 1
174 match_len = iend - istart
175 qstart = qend - match_len
176 yield rid, qstart, qend, istart, iend
177
178
179def get_matches(tokens, qbegin, automaton):

Callers 1

exact_matchFunction · 0.85

Calls 2

get_matchesFunction · 0.70
logger_debugFunction · 0.70

Tested by

no test coverage detected