3131
3232- containment: a small match is contained in a larger match
3333- overlap: based on a level of overlap between matches
34- - various spurrious matches rules based on length, required content, etc.
34+ - various spurious matches rules based on length, required content, etc.
3535- false positives
3636
3737The filter functions are executed in a specific sequence over the list of matches.
4848TRACE_FILTER_SHORT = False
4949TRACE_FILTER_RULE_MIN_COVERAGE = False
5050TRACE_FILTER_BELOW_MIN_SCORE = False
51- TRACE_FILTER_SINGLE_WORD_BINARY = False
51+ TRACE_FILTER_SINGLE_WORD_GIBBERISH = False
5252TRACE_SET_LINES = False
5353TRACE_KEY_PHRASES = False
5454TRACE_REGIONS = False
@@ -81,7 +81,7 @@ def logger_debug(*args): pass
8181 or TRACE_SET_LINES
8282 or TRACE_MATCHED_TEXT
8383 or TRACE_MATCHED_TEXT_DETAILS
84- or TRACE_FILTER_SINGLE_WORD_BINARY
84+ or TRACE_FILTER_SINGLE_WORD_GIBBERISH
8585 or TRACE_KEY_PHRASES
8686 or TRACE_REGIONS
8787 or TRACE_FILTER_LICENSE_LIST
@@ -128,7 +128,7 @@ class DiscardReason(IntEnum):
128128 SPURIOUS_SINGLE_TOKEN = 3
129129 TOO_SHORT = 4
130130 SCATTERED_ON_TOO_MANY_LINES = 5
131- INVALID_SINGLE_WORD_IN_BINARY = 6
131+ INVALID_SINGLE_WORD_GIBBERISH = 6
132132 SPURIOUS = 7
133133 CONTAINED = 8
134134 OVERLAPPING = 9
@@ -1697,24 +1697,25 @@ def filter_spurious_matches(
16971697 return kept , discarded
16981698
16991699
1700- def filter_invalid_matches_to_single_word_in_binaries (
1700+ def filter_invalid_matches_to_single_word_gibberish (
17011701 matches ,
1702- trace = TRACE_FILTER_SINGLE_WORD_BINARY ,
1703- reason = DiscardReason .INVALID_SINGLE_WORD_IN_BINARY ,
1702+ trace = TRACE_FILTER_SINGLE_WORD_GIBBERISH ,
1703+ reason = DiscardReason .INVALID_SINGLE_WORD_GIBBERISH ,
17041704):
17051705 """
17061706 Return a filtered list of kept LicenseMatch matches and a list of
17071707 discardable matches given a `matches` list of LicenseMatch by removing
1708- matches in binary files considered as invalid under these conditions:
1708+ gibberish matches considered as invalid under these conditions:
17091709
1710- - the match is for a binary file
1711- - the matched rule that has a single word (length 1)
1710+ - the scanned file is a binary file (we could relax this in the future
1711+ - the matched rule has a single word (length 1)
1712+ - the matched rule "is_license_reference: yes"
17121713 - the matched rule has a low relevance, e.g., under 75
17131714 - the matched text has either:
17141715 - one or more leading or trailing punctuations (except for +)
17151716 unless this has a high relevance and the rule is contained as-is
17161717 in the matched text (considering case)
1717- - mixed upper and lower case charcaters (but not a Title case) unless
1718+ - mixed upper and lower case characters (but not a Title case) unless
17181719 exactly the same mixed case as the rule text
17191720 """
17201721 kept = []
@@ -1724,11 +1725,7 @@ def filter_invalid_matches_to_single_word_in_binaries(
17241725
17251726 for match in matches :
17261727 rule = match .rule
1727- if (
1728- rule .length == 1
1729- and match .query .is_binary
1730- and rule .is_license_reference
1731- ):
1728+ if rule .length == 1 and rule .is_license_reference and match .query .is_binary :
17321729 matched_text = match .matched_text (
17331730 whole_lines = False ,
17341731 highlight = False ,
@@ -1738,7 +1735,7 @@ def filter_invalid_matches_to_single_word_in_binaries(
17381735
17391736 if trace :
17401737 logger_debug (
1741- ' ==> POTENTIAL INVALID_BINARY :' , match ,
1738+ ' ==> POTENTIAL INVALID GIBBERISH :' , match ,
17421739 'matched_text:' , repr (matched_text ),
17431740 'rule_text:' , repr (rule_text )
17441741 )
@@ -1750,7 +1747,7 @@ def filter_invalid_matches_to_single_word_in_binaries(
17501747
17511748 if is_invalid_short_match (matched_text , rule_text , max_diff = max_diff ):
17521749 if trace :
1753- logger_debug (' ==> DISCARDING INVALID_BINARY :' , match )
1750+ logger_debug (' ==> DISCARDING INVALID GIBBERISH :' , match )
17541751 discarded_append (match )
17551752 match .discard_reason = reason
17561753 continue
@@ -1808,7 +1805,7 @@ def is_invalid_short_match(
18081805 matched_text ,
18091806 rule_text ,
18101807 max_diff = 0 ,
1811- trace = TRACE_FILTER_SINGLE_WORD_BINARY ,
1808+ trace = TRACE_FILTER_SINGLE_WORD_GIBBERISH ,
18121809):
18131810 """
18141811 Return True if the ``matched_text`` given a ``rule_text`` is invalid.
@@ -1842,6 +1839,8 @@ def is_invalid_short_match(
18421839 False
18431840 >>> is_invalid_short_match("gpl) &", "GPL")
18441841 True
1842+ >>> is_invalid_short_match("GPLv2(", "GPLv2")
1843+ True
18451844 """
18461845 if trace :
18471846 logger_debug (
@@ -1973,9 +1972,9 @@ def filter_matches_missing_key_phrases(
19731972 continue
19741973
19751974 if is_continuous and not match .is_continuous ():
1976- kept_append (match )
1975+ discarded_append (match )
19771976 if trace :
1978- logger_debug (' ==> KEEPING , IS_CONTINUOUS BUT NOT IS_CONTINUOUS' )
1977+ logger_debug (' ==> DISCARDING , IS_CONTINUOUS BUT NOT IS_CONTINUOUS' )
19791978 continue
19801979
19811980 ispan = match .ispan
@@ -2528,9 +2527,9 @@ def _log(_matches, _discarded, msg):
25282527 all_discarded_extend (discarded )
25292528 _log (matches , discarded , 'ACCEPTABLE IF NOT SHORT SCATTERED' )
25302529
2531- matches , discarded = filter_invalid_matches_to_single_word_in_binaries (matches )
2530+ matches , discarded = filter_invalid_matches_to_single_word_gibberish (matches )
25322531 all_discarded_extend (discarded )
2533- _log (matches , discarded , 'MORE THAN ONE NON INVALID TOKEN IN BINARY ' )
2532+ _log (matches , discarded , 'MORE THAN ONE NON INVALID GIBBERISH TOKEN ' )
25342533
25352534 matches , discarded = filter_spurious_matches (matches )
25362535 all_discarded_extend (discarded )
0 commit comments