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

Function match_sequence

src/licensedcode/match_seq.py:48–156  ·  view source on GitHub ↗

Return a list of LicenseMatch by matching the `query_run` tokens sequence starting at `start_offset` against the `idx` index for the candidate `rule`. Stop processing when reachin the deadline time.

(
    idx,
    rule,
    query_run,
    high_postings,
    start_offset=0,
    match_blocks=None,
    deadline=sys.maxsize,
)

Source from the content-addressed store, hash-verified

46
47
48def match_sequence(
49 idx,
50 rule,
51 query_run,
52 high_postings,
53 start_offset=0,
54 match_blocks=None,
55 deadline=sys.maxsize,
56):
57 """
58 Return a list of LicenseMatch by matching the `query_run` tokens sequence
59 starting at `start_offset` against the `idx` index for the candidate `rule`.
60 Stop processing when reachin the deadline time.
61 """
62 if not rule:
63 return []
64
65 if not match_blocks:
66 try:
67 # Use Cython seq.py implementation
68 from cyseq import match_blocks
69 except ImportError:
70 # Use Python seq.py if it is not available
71 from licensedcode.seq import match_blocks
72
73 rid = rule.rid
74 itokens = idx.tids_by_rid[rid]
75
76 len_legalese = idx.len_legalese
77
78 qbegin = query_run.start + start_offset
79 qfinish = query_run.end
80 qtokens = query_run.query.tokens
81 query = query_run.query
82
83 matches = []
84 qstart = qbegin
85
86 # match as long as long we find alignments and have high matchable tokens
87 # this allows to find repeated instances of the same rule in the query run
88
89 while qstart <= qfinish:
90
91 if TRACE2:
92 logger_debug('\n\nmatch_seq:==========================LOOP=============================')
93
94 if not query_run.is_matchable(include_low=False):
95 break
96
97 if TRACE2:
98 logger_debug('match_seq:running block_matches:', 'a_start:', qstart, 'a_end', qfinish + 1)
99
100 block_matches = match_blocks(
101 a=qtokens, b=itokens, a_start=qstart, a_end=qfinish + 1,
102 b2j=high_postings, len_good=len_legalese,
103 matchables=query_run.matchables)
104
105 if not block_matches:

Callers

nothing calls this directly

Calls 7

match_blocksFunction · 0.90
SpanClass · 0.90
LicenseMatchClass · 0.90
get_textsFunction · 0.90
is_matchableMethod · 0.80
logger_debugFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected