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

Function get_match

etc/scripts/licenses/synclic.py:227–276  ·  view source on GitHub ↗

Return a tuple of (license key, True if exact match, match score, match text) e.g.: - top matched license key or None, - True if this an exact match, False if the match is ok, None if the match is weak, - match score or 0 or None - matched text or None

(text)

Source from the content-addressed store, hash-verified

225
226
227def get_match(text):
228 """
229 Return a tuple of (license key, True if exact match, match score, match text)
230 e.g.:
231 - top matched license key or None,
232 - True if this an exact match, False if the match is ok, None if the match is weak,
233 - match score or 0 or None
234 - matched text or None
235 """
236
237 from licensedcode.cache import get_index
238
239 idx = get_index()
240 matches = list(idx.match(query_string=text, min_score=80))
241 if not matches:
242 return None, None, 0, None
243
244 match = matches[0]
245 matched_text = match.matched_text(whole_lines=False)
246 query = match.query
247 query_len = len(query.whole_query_run().tokens)
248 rule = match.rule
249 rule_licenses = rule.license_keys()
250 key = rule_licenses[0]
251
252 is_exact = (
253 len(matches) == 1
254 and rule.is_from_license
255 and len(rule_licenses) == 1
256 and match.matcher == "1-hash"
257 and match.score() == 100
258 and match.len() == query_len
259 )
260
261 if is_exact:
262 return key, True, 100, matched_text
263
264 is_ok = len(rule_licenses) == 1 and match.coverage() > 95 and match.score() > 95
265 if is_ok:
266 return key, False, match.score(), matched_text
267
268 is_weak = len(rule_licenses) == 1 and match.coverage() > 90 and match.score() > 90
269 if is_weak:
270 return key, None, match.score(), matched_text
271
272 if match.score() > 85:
273 # junk match
274 return key, -1, match.score(), matched_text
275 else:
276 return None, None, None, None
277
278
279def get_response(url, headers, params):

Callers 1

Calls 8

get_indexFunction · 0.90
matchMethod · 0.80
whole_query_runMethod · 0.80
license_keysMethod · 0.80
matched_textMethod · 0.45
scoreMethod · 0.45
lenMethod · 0.45
coverageMethod · 0.45

Tested by

no test coverage detected