Skip to content

Commit 1f5a194

Browse files
committed
write function such that we get extra-words for 2-aho
Signed-off-by: Alok Kumar <alokkumarjipura9973@gmail.com>
1 parent 3db9bac commit 1f5a194

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/licensedcode/detection.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,27 @@ def is_correct_detection_non_unknown(license_matches):
10551055
are correct/perfect license detections and also there aren't any unknowns.
10561056
"""
10571057
return (
1058-
is_correct_detection(license_matches)
1058+
is_correct_detection_2(license_matches)
10591059
and not has_unknown_matches(license_matches)
10601060
)
10611061

1062+
def is_correct_detection_2(license_matches):
1063+
"""
1064+
Return True if all the matches in ``license_matches`` List of LicenseMatch
1065+
are perfect license detections, and the matcher is always either `1-hash`
1066+
or `1-spdx-id`.
1067+
"""
1068+
matchers = (license_match.matcher for license_match in license_matches)
1069+
is_match_coverage_perfect = [
1070+
license_match.coverage() == 100
1071+
for license_match in license_matches
1072+
]
1073+
1074+
return (
1075+
all(matcher in ("1-hash", "1-spdx-id") for matcher in matchers)
1076+
and all(is_match_coverage_perfect)
1077+
)
1078+
10621079

10631080
def is_correct_detection(license_matches):
10641081
"""
@@ -1734,7 +1751,7 @@ def analyze_detection(license_matches, package_license=False):
17341751
):
17351752
return DetectionCategory.LICENSE_CLUES.value
17361753

1737-
# Case where all matches have `matcher` as `1-hash` or `4-spdx-id`
1754+
# Case where all matches have `matcher` as `1-hash` or `1-spdx-id`
17381755
elif is_correct_detection_non_unknown(license_matches=license_matches):
17391756
return DetectionCategory.PERFECT_DETECTION.value
17401757

tests/licensedcode/data/plugin_license/extra-words/scan-extra-words-2-aho-license.expected.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"license_expression": "bsd-new",
66
"license_expression_spdx": "BSD-3-Clause",
77
"detection_count": 1,
8-
"detection_log": [],
8+
"detection_log": [
9+
"extra-words"
10+
],
911
"reference_matches": [
1012
{
1113
"license_expression": "bsd-new",
@@ -54,7 +56,9 @@
5456
"matched_text_diagnostics": "Redistribution and use in source and binary forms, with or without\r\nmodification, are permitted provided that the following conditions are met:\r\n\r\n* Redistributions of source code must retain the above copyright notice, this\r\n list of conditions and the following disclaimer.\r\n\r\n* Redistributions in binary form must reproduce the above copyright notice,\r\n this list of conditions and the following disclaimer in the documentation\r\n and/or other materials provided with the distribution.\r\n\r\n* Neither the name of [filesize] nor the names of its\r\n contributors may be used to endorse or promote products derived from\r\n this software without specific prior written permission.\r\n\r\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\r\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
5557
}
5658
],
57-
"detection_log": [],
59+
"detection_log": [
60+
"extra-words"
61+
],
5862
"identifier": "bsd_new-fbfc5955-0c63-4c98-2ce9-08e1e1796f50"
5963
}
6064
],

0 commit comments

Comments
 (0)