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

Function hash_match

src/licensedcode/match_hash.py:59–87  ·  view source on GitHub ↗

Return a sequence of LicenseMatch by matching the query_tokens sequence against the idx index.

(idx, query_run, **kwargs)

Source from the content-addressed store, hash-verified

57
58
59def hash_match(idx, query_run, **kwargs):
60 """
61 Return a sequence of LicenseMatch by matching the query_tokens sequence
62 against the idx index.
63 """
64 logger_debug('match_hash: start....')
65 matches = []
66 query_hash = tokens_hash(query_run.tokens)
67 rid = idx.rid_by_hash.get(query_hash)
68 if rid is not None:
69 rule = idx.rules_by_rid[rid]
70 itokens = idx.tids_by_rid[rid]
71 len_legalese = idx.len_legalese
72 logger_debug('match_hash: Match:', rule.identifier)
73 qspan = Span(range(query_run.start, query_run.end + 1))
74 ispan = Span(range(0, rule.length))
75 hispan = Span(p for p in ispan if itokens[p] < len_legalese)
76 match = LicenseMatch(
77 rule=rule,
78 qspan=qspan,
79 ispan=ispan,
80 hispan=hispan,
81 query_run_start=query_run.start,
82 matcher=MATCH_HASH,
83 matcher_order=MATCH_HASH_ORDER,
84 query=query_run.query,
85 )
86 matches.append(match)
87 return matches

Callers

nothing calls this directly

Calls 6

SpanClass · 0.90
LicenseMatchClass · 0.90
tokens_hashFunction · 0.85
logger_debugFunction · 0.70
getMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected