Skip to content

Commit 467449a

Browse files
Merge pull request #4009 from alexzurbonsen/fix-regression-false-positive-detection
Fix false positive detection heuristics
2 parents 4bca665 + 9872108 commit 467449a

File tree

2 files changed

+55
-141
lines changed

2 files changed

+55
-141
lines changed

src/licensedcode/detection.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,26 +1164,22 @@ def is_false_positive(license_matches, package_license=False):
11641164
# FIXME: actually run copyright detection here?
11651165
copyright_words = ["copyright", "(c)"]
11661166
has_copyrights = all(
1167-
True
1168-
for license_match in license_matches
1169-
if any(
1170-
True
1167+
any(
1168+
word in license_match.matched_text().lower()
11711169
for word in copyright_words
1172-
if word in license_match.matched_text().lower()
1173-
)
1170+
)
1171+
for license_match in license_matches
11741172
)
11751173
has_full_relevance = all(
1176-
True
1174+
license_match.rule.relevance == 100
11771175
for license_match in license_matches
1178-
if license_match.rule.relevance == 100
11791176
)
11801177
if has_copyrights or has_full_relevance:
11811178
return False
11821179

11831180
has_low_relevance = all(
1184-
True
1181+
license_match.rule.relevance < 60
11851182
for license_match in license_matches
1186-
if license_match.rule.relevance < 60
11871183
)
11881184

11891185
start_line_region = min(

tests/licensedcode/data/plugin_license/scan/ffmpeg-license.expected.json

Lines changed: 49 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -82,47 +82,6 @@
8282
}
8383
]
8484
},
85-
{
86-
"identifier": "gpl_2_0_and_lgpl_2_0_plus-e597690d-3d55-0948-8697-914f460389e8",
87-
"license_expression": "gpl-2.0 AND lgpl-2.0-plus",
88-
"license_expression_spdx": "GPL-2.0-only AND LGPL-2.0-or-later",
89-
"detection_count": 1,
90-
"detection_log": [],
91-
"reference_matches": [
92-
{
93-
"license_expression": "gpl-2.0",
94-
"license_expression_spdx": "GPL-2.0-only",
95-
"from_file": "ffmpeg-LICENSE.md",
96-
"start_line": 100,
97-
"end_line": 100,
98-
"matcher": "2-aho",
99-
"score": 100.0,
100-
"matched_length": 1,
101-
"match_coverage": 100.0,
102-
"rule_relevance": 100,
103-
"rule_identifier": "gpl-2.0_bare_single_word.RULE",
104-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/gpl-2.0_bare_single_word.RULE",
105-
"matched_text": "are incompatible with the GPLv2 and v3. We do not know for certain if their",
106-
"matched_text_diagnostics": "GPLv2"
107-
},
108-
{
109-
"license_expression": "lgpl-2.0-plus",
110-
"license_expression_spdx": "LGPL-2.0-or-later",
111-
"from_file": "ffmpeg-LICENSE.md",
112-
"start_line": 101,
113-
"end_line": 101,
114-
"matcher": "2-aho",
115-
"score": 60.0,
116-
"matched_length": 1,
117-
"match_coverage": 100.0,
118-
"rule_relevance": 60,
119-
"rule_identifier": "lgpl_bare_single_word.RULE",
120-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
121-
"matched_text": "licenses are compatible with the LGPL.",
122-
"matched_text_diagnostics": "LGPL."
123-
}
124-
]
125-
},
12685
{
12786
"identifier": "ijg_and_mit-e50613dc-8a09-65cc-c498-5d9527795382",
12887
"license_expression": "ijg AND mit",
@@ -182,31 +141,6 @@
182141
}
183142
]
184143
},
185-
{
186-
"identifier": "lgpl_2_0_plus-e66c5b24-33ce-ea1b-0e3b-28952361ec32",
187-
"license_expression": "lgpl-2.0-plus",
188-
"license_expression_spdx": "LGPL-2.0-or-later",
189-
"detection_count": 1,
190-
"detection_log": [],
191-
"reference_matches": [
192-
{
193-
"license_expression": "lgpl-2.0-plus",
194-
"license_expression_spdx": "LGPL-2.0-or-later",
195-
"from_file": "ffmpeg-LICENSE.md",
196-
"start_line": 104,
197-
"end_line": 104,
198-
"matcher": "2-aho",
199-
"score": 60.0,
200-
"matched_length": 1,
201-
"match_coverage": 100.0,
202-
"rule_relevance": 60,
203-
"rule_identifier": "lgpl_bare_single_word.RULE",
204-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
205-
"matched_text": "be under a complex license mix that is more restrictive than the LGPL and that",
206-
"matched_text_diagnostics": "LGPL"
207-
}
208-
]
209-
},
210144
{
211145
"identifier": "lgpl_2_1_plus_and_other_permissive_and_gpl_2_0_plus-666058ef-8c38-3b17-d8e7-448b304de833",
212146
"license_expression": "lgpl-2.1-plus AND other-permissive AND gpl-2.0-plus",
@@ -294,8 +228,8 @@
294228
{
295229
"path": "ffmpeg-LICENSE.md",
296230
"type": "file",
297-
"detected_license_expression": "(lgpl-2.1-plus AND other-permissive AND gpl-2.0-plus) AND (lgpl-3.0 AND lgpl-3.0-plus AND (lgpl-3.0 AND gpl-3.0)) AND (ijg AND mit) AND gpl-1.0-plus AND (gpl-2.0 AND apache-2.0 AND lgpl-3.0-plus) AND (gpl-2.0 AND lgpl-2.0-plus) AND lgpl-2.0-plus",
298-
"detected_license_expression_spdx": "(LGPL-2.1-or-later AND LicenseRef-scancode-other-permissive AND GPL-2.0-or-later) AND (LGPL-3.0-only AND LGPL-3.0-or-later AND (LGPL-3.0-only AND GPL-3.0-only)) AND (IJG AND MIT) AND GPL-1.0-or-later AND (GPL-2.0-only AND Apache-2.0 AND LGPL-3.0-or-later) AND (GPL-2.0-only AND LGPL-2.0-or-later) AND LGPL-2.0-or-later",
231+
"detected_license_expression": "(lgpl-2.1-plus AND other-permissive AND gpl-2.0-plus) AND (lgpl-3.0 AND lgpl-3.0-plus AND (lgpl-3.0 AND gpl-3.0)) AND (ijg AND mit) AND gpl-1.0-plus AND (gpl-2.0 AND apache-2.0 AND lgpl-3.0-plus)",
232+
"detected_license_expression_spdx": "(LGPL-2.1-or-later AND LicenseRef-scancode-other-permissive AND GPL-2.0-or-later) AND (LGPL-3.0-only AND LGPL-3.0-or-later AND (LGPL-3.0-only AND GPL-3.0-only)) AND (IJG AND MIT) AND GPL-1.0-or-later AND (GPL-2.0-only AND Apache-2.0 AND LGPL-3.0-or-later)",
299233
"license_detections": [
300234
{
301235
"license_expression": "lgpl-2.1-plus AND other-permissive AND gpl-2.0-plus",
@@ -514,73 +448,41 @@
514448
],
515449
"detection_log": [],
516450
"identifier": "gpl_2_0_and_apache_2_0_and_lgpl_3_0_plus-c2393e5a-e531-304f-58a9-a6431d46d214"
517-
},
451+
}
452+
],
453+
"license_clues": [
518454
{
519-
"license_expression": "gpl-2.0 AND lgpl-2.0-plus",
520-
"license_expression_spdx": "GPL-2.0-only AND LGPL-2.0-or-later",
521-
"matches": [
522-
{
523-
"license_expression": "gpl-2.0",
524-
"license_expression_spdx": "GPL-2.0-only",
525-
"from_file": "ffmpeg-LICENSE.md",
526-
"start_line": 100,
527-
"end_line": 100,
528-
"matcher": "2-aho",
529-
"score": 100.0,
530-
"matched_length": 1,
531-
"match_coverage": 100.0,
532-
"rule_relevance": 100,
533-
"rule_identifier": "gpl-2.0_bare_single_word.RULE",
534-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/gpl-2.0_bare_single_word.RULE",
535-
"matched_text": "are incompatible with the GPLv2 and v3. We do not know for certain if their",
536-
"matched_text_diagnostics": "GPLv2"
537-
},
538-
{
539-
"license_expression": "lgpl-2.0-plus",
540-
"license_expression_spdx": "LGPL-2.0-or-later",
541-
"from_file": "ffmpeg-LICENSE.md",
542-
"start_line": 101,
543-
"end_line": 101,
544-
"matcher": "2-aho",
545-
"score": 60.0,
546-
"matched_length": 1,
547-
"match_coverage": 100.0,
548-
"rule_relevance": 60,
549-
"rule_identifier": "lgpl_bare_single_word.RULE",
550-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
551-
"matched_text": "licenses are compatible with the LGPL.",
552-
"matched_text_diagnostics": "LGPL."
553-
}
554-
],
555-
"detection_log": [],
556-
"identifier": "gpl_2_0_and_lgpl_2_0_plus-e597690d-3d55-0948-8697-914f460389e8"
455+
"license_expression": "gpl-2.0",
456+
"license_expression_spdx": "GPL-2.0-only",
457+
"from_file": "ffmpeg-LICENSE.md",
458+
"start_line": 100,
459+
"end_line": 100,
460+
"matcher": "2-aho",
461+
"score": 100.0,
462+
"matched_length": 1,
463+
"match_coverage": 100.0,
464+
"rule_relevance": 100,
465+
"rule_identifier": "gpl-2.0_bare_single_word.RULE",
466+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/gpl-2.0_bare_single_word.RULE",
467+
"matched_text": "are incompatible with the GPLv2 and v3. We do not know for certain if their",
468+
"matched_text_diagnostics": "GPLv2"
557469
},
558470
{
559471
"license_expression": "lgpl-2.0-plus",
560472
"license_expression_spdx": "LGPL-2.0-or-later",
561-
"matches": [
562-
{
563-
"license_expression": "lgpl-2.0-plus",
564-
"license_expression_spdx": "LGPL-2.0-or-later",
565-
"from_file": "ffmpeg-LICENSE.md",
566-
"start_line": 104,
567-
"end_line": 104,
568-
"matcher": "2-aho",
569-
"score": 60.0,
570-
"matched_length": 1,
571-
"match_coverage": 100.0,
572-
"rule_relevance": 60,
573-
"rule_identifier": "lgpl_bare_single_word.RULE",
574-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
575-
"matched_text": "be under a complex license mix that is more restrictive than the LGPL and that",
576-
"matched_text_diagnostics": "LGPL"
577-
}
578-
],
579-
"detection_log": [],
580-
"identifier": "lgpl_2_0_plus-e66c5b24-33ce-ea1b-0e3b-28952361ec32"
581-
}
582-
],
583-
"license_clues": [
473+
"from_file": "ffmpeg-LICENSE.md",
474+
"start_line": 101,
475+
"end_line": 101,
476+
"matcher": "2-aho",
477+
"score": 60.0,
478+
"matched_length": 1,
479+
"match_coverage": 100.0,
480+
"rule_relevance": 60,
481+
"rule_identifier": "lgpl_bare_single_word.RULE",
482+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
483+
"matched_text": "licenses are compatible with the LGPL.",
484+
"matched_text_diagnostics": "LGPL."
485+
},
584486
{
585487
"license_expression": "proprietary-license",
586488
"license_expression_spdx": "LicenseRef-scancode-proprietary-license",
@@ -596,10 +498,26 @@
596498
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/proprietary-license_490.RULE",
597499
"matched_text": "If you wish to enable these libraries, pass --enable-nonfree to configure.",
598500
"matched_text_diagnostics": "enable-nonfree"
501+
},
502+
{
503+
"license_expression": "lgpl-2.0-plus",
504+
"license_expression_spdx": "LGPL-2.0-or-later",
505+
"from_file": "ffmpeg-LICENSE.md",
506+
"start_line": 104,
507+
"end_line": 104,
508+
"matcher": "2-aho",
509+
"score": 60.0,
510+
"matched_length": 1,
511+
"match_coverage": 100.0,
512+
"rule_relevance": 60,
513+
"rule_identifier": "lgpl_bare_single_word.RULE",
514+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
515+
"matched_text": "be under a complex license mix that is more restrictive than the LGPL and that",
516+
"matched_text_diagnostics": "LGPL"
599517
}
600518
],
601519
"percentage_of_license_text": 34.78,
602520
"scan_errors": []
603521
}
604522
]
605-
}
523+
}

0 commit comments

Comments
 (0)