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

Function refine_matches

src/licensedcode/match.py:2691–2832  ·  view source on GitHub ↗

Return a filtered list of kept LicenseMatch matches and a list of discardable matches given a `matches` list of LicenseMatch by removing matches that do not mee certain criteria as defined in multiple filters.

(
    matches,
    query=None,
    min_score=0,
    filter_false_positive=True,
    merge=True,
    trace_basic=TRACE,
    trace=TRACE_REFINE,
)

Source from the content-addressed store, hash-verified

2689
2690
2691def refine_matches(
2692 matches,
2693 query=None,
2694 min_score=0,
2695 filter_false_positive=True,
2696 merge=True,
2697 trace_basic=TRACE,
2698 trace=TRACE_REFINE,
2699):
2700 """
2701 Return a filtered list of kept LicenseMatch matches and a list of
2702 discardable matches given a `matches` list of LicenseMatch by removing
2703 matches that do not mee certain criteria as defined in multiple filters.
2704 """
2705
2706 if trace_basic:
2707 logger_debug()
2708 logger_debug(' #####refine_matches: STARTING matches#', len(matches))
2709 if trace:
2710 for m in matches:
2711 logger_debug(m)
2712 if not matches:
2713 return [], []
2714
2715 all_discarded = []
2716 all_discarded_extend = all_discarded.extend
2717
2718 if merge:
2719 matches = merge_matches(matches)
2720
2721 if trace_basic:
2722 logger_debug(' ##### refine_matches: STARTING MERGED_matches#:', len(matches))
2723
2724 def _log(_matches, _discarded, msg):
2725 if trace_basic:
2726 logger_debug(' #####refine_matches: KEPT', msg, '#', len(matches))
2727
2728 if trace:
2729 for m in matches:
2730 logger_debug(m)
2731
2732 if trace_basic:
2733 logger_debug(' #####refine_matches: DISCARDED NOT', msg, '#', len(_discarded))
2734
2735 if trace:
2736 for m in matches:
2737 logger_debug(m)
2738
2739 set_matched_lines(matches, query.line_by_pos)
2740
2741 # FIXME: we should have only a single loop on all the matches at once!!
2742 # and not 10's of loops!!!
2743
2744 matches, discarded = filter_matches_missing_required_phrases(matches)
2745 all_discarded_extend(discarded)
2746 _log(matches, discarded, 'HAS REQUIRED PHRASES')
2747
2748 matches, discarded = filter_spurious_matches(matches)

Callers

nothing calls this directly

Tested by

no test coverage detected