Skip to content

Commit e9372e6

Browse files
committed
Improve match filtering #695
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 9fd9cf8 commit e9372e6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/licensedcode/match.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def merge_matches(matches, max_dist=MAX_DIST):
437437
for rid, rule_matches in matches_by_rule:
438438
if TRACE_MERGE: logger_debug('merge_matches: processing rule:', rid)
439439
rlen = rule_matches[0].rule.length
440-
max_rlen_dist = min(rlen // 5, MAX_DIST)
440+
max_rlen_dist = min((rlen // 5) or 1, MAX_DIST)
441441

442442
# compare two matches in the sorted sequence: current and next
443443
i = 0
@@ -585,7 +585,7 @@ def filter_contained_matches(matches):
585585

586586
if TRACE_FILTER_CONTAINS: print('filter_contained_matches: number of matches to process:', len(matches))
587587
if TRACE_FILTER_CONTAINS:
588-
print('filter_contained_matches: matches')
588+
print('filter_contained_matches: initial matches')
589589
map(print, matches)
590590

591591
# compare two matches in the sorted sequence: current and next match
@@ -596,15 +596,15 @@ def filter_contained_matches(matches):
596596
while j < len(matches):
597597
current_match = matches[i]
598598
next_match = matches[j]
599+
if TRACE_FILTER_CONTAINS: logger_debug('---> filter_contained_matches: current: i=', i, current_match)
600+
if TRACE_FILTER_CONTAINS: logger_debug('---> filter_contained_matches: next: j=', j, next_match)
599601

600602
# TODO: is this really correct?
601603
# stop when no overlap: Touching and overlapping matches have a zero distance.
602604
if current_match.qdistance_to(next_match):
603-
if TRACE_FILTER_CONTAINS: logger_debug(' ---> ###filter_contained_matches: matches have a distance: NO OVERLAP POSSIBLE\n')
604-
break
605-
606-
if TRACE_FILTER_CONTAINS: logger_debug('---> filter_contained_matches: current: i=', i, current_match)
607-
if TRACE_FILTER_CONTAINS: logger_debug('---> filter_contained_matches: next: j=', j, next_match)
605+
if TRACE_FILTER_CONTAINS: logger_debug(' ---> ###filter_contained_matches: matches have a distance: NO OVERLAP POSSIBLE -->', 'qdist:', current_match.qdistance_to(next_match))
606+
j += 1
607+
continue
608608

609609
# equals matches
610610
if current_match.qspan == next_match.qspan:

0 commit comments

Comments
 (0)