Skip to content

Commit

Permalink
Add new sample_matches attribute to top-level detection
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
  • Loading branch information
AyanSinhaMahapatra committed Dec 7, 2023
1 parent dbffe43 commit a1fc5d8
Show file tree
Hide file tree
Showing 101 changed files with 8,717 additions and 316 deletions.
8 changes: 7 additions & 1 deletion src/licensedcode/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ def to_dict(

if include_text:
result['matched_text'] = matched_text

return result


Expand Down Expand Up @@ -917,7 +918,12 @@ def dict_fields(attr, value):

return True

return attr.asdict(self, filter=dict_fields)
detection_mapping = attr.asdict(self, filter=dict_fields)
detection_mapping["sample_matches"] = [
match.to_dict(include_text=True)
for match in self.matches
]
return detection_mapping

def get_license_detection_object(self):
return LicenseDetection(
Expand Down
18 changes: 17 additions & 1 deletion tests/cluecode/data/plugin_filter_clues/filtered-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
{
"identifier": "apache_1_1-1712efcb-d696-b5e4-214d-b2ab69680c2a",
"license_expression": "apache-1.1",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 96.07,
"from_file": "LICENSE",
"start_line": 7,
"end_line": 70,
"matched_length": 367,
"match_coverage": 100.0,
"matcher": "3-seq",
"license_expression": "apache-1.1",
"rule_identifier": "apache-1.1_63.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-1.1_63.RULE",
"matched_text": null
}
]
}
],
"files": [
Expand Down
18 changes: 17 additions & 1 deletion tests/cluecode/data/plugin_filter_clues/filtered-expected2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
{
"identifier": "pygres_2_2-04f085e8-3db1-f9e2-8dde-7ba8a7ba619a",
"license_expression": "pygres-2.2",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 100.0,
"from_file": "LICENSE2",
"start_line": 7,
"end_line": 22,
"matched_length": 145,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "pygres-2.2",
"rule_identifier": "pygres-2.2_2.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/pygres-2.2_2.RULE",
"matched_text": null
}
]
}
],
"files": [
Expand Down
18 changes: 17 additions & 1 deletion tests/cluecode/data/plugin_filter_clues/filtered-expected3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
{
"identifier": "pcre-c61d8210-7748-d787-5e3e-fd64c6cd6b6a",
"license_expression": "pcre",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 100.0,
"from_file": "LICENSE3",
"start_line": 1,
"end_line": 47,
"matched_length": 303,
"match_coverage": 100.0,
"matcher": "1-hash",
"license_expression": "pcre",
"rule_identifier": "pcre.LICENSE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pcre.LICENSE",
"matched_text": null
}
]
}
],
"files": [
Expand Down
208 changes: 198 additions & 10 deletions tests/formattedcode/data/common/manifests-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,52 +472,240 @@
{
"identifier": "apache_2_0-d66ab77d-a5cc-7104-e702-dc7df61fe9e8",
"license_expression": "apache-2.0",
"detection_count": 3
"detection_count": 3,
"sample_matches": [
{
"score": 100.0,
"from_file": "manifests/npm-license-mapping/package.json",
"start_line": 20,
"end_line": 20,
"matched_length": 3,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "apache-2.0",
"rule_identifier": "spdx_license_id_apache-2.0_for_apache-2.0.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/spdx_license_id_apache-2.0_for_apache-2.0.RULE",
"matched_text": null
}
]
},
{
"identifier": "apache_2_0-ec759ae0-ea5a-f138-793e-388520e080c0",
"license_expression": "apache-2.0",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 100.0,
"from_file": "manifests/npm-license-mapping/package.json",
"start_line": 6,
"end_line": 6,
"matched_length": 4,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "apache-2.0",
"rule_identifier": "apache-2.0_65.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-2.0_65.RULE",
"matched_text": null
}
]
},
{
"identifier": "cddl_1_0-c6dbef4d-659c-289f-5ee9-1ca0278edad6",
"license_expression": "cddl-1.0",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 16.0,
"from_file": "manifests/maven/persistence-api-1.0.pom",
"start_line": 17,
"end_line": 19,
"matched_length": 3,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "unknown-license-reference",
"rule_identifier": "license-intro_72.RULE",
"rule_relevance": 16,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/license-intro_72.RULE",
"matched_text": null
},
{
"score": 82.35,
"from_file": "manifests/maven/persistence-api-1.0.pom",
"start_line": 18,
"end_line": 20,
"matched_length": 14,
"match_coverage": 82.35,
"matcher": "3-seq",
"license_expression": "cddl-1.0",
"rule_identifier": "cddl-1.0_32.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/cddl-1.0_32.RULE",
"matched_text": null
}
]
},
{
"identifier": "cddl_1_0-dd3dd7df-afca-6a5e-492c-f7b279fdd880",
"license_expression": "cddl-1.0",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 100.0,
"from_file": "manifests/maven/persistence-api-1.0.pom",
"start_line": 1,
"end_line": 1,
"matched_length": 8,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "cddl-1.0",
"rule_identifier": "cddl-1.0.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/cddl-1.0.RULE",
"matched_text": "- name: Common Development and Distribution License (CDDL) v1.0"
},
{
"score": 100.0,
"from_file": "manifests/maven/persistence-api-1.0.pom",
"start_line": 2,
"end_line": 2,
"matched_length": 7,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "cddl-1.0",
"rule_identifier": "cddl-1.0_4.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/cddl-1.0_4.RULE",
"matched_text": " url: http://www.sun.com/cddl/cddl.html"
}
]
},
{
"identifier": "lgpl_3_0-272571eb-5e68-95b6-ddb0-71de2d8df321",
"license_expression": "lgpl-3.0",
"detection_count": 2
"detection_count": 2,
"sample_matches": [
{
"score": 100.0,
"from_file": "manifests/pypi/bluepyopt_setup.py",
"start_line": 74,
"end_line": 75,
"matched_length": 10,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "lgpl-3.0",
"rule_identifier": "pypi_gnu_lesser_general_public_license_v3.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/pypi_gnu_lesser_general_public_license_v3.RULE",
"matched_text": null
}
]
},
{
"identifier": "lgpl_3_0-121be3c2-9c80-df84-d3da-8f674e4125c0",
"license_expression": "lgpl-3.0",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 100.0,
"from_file": "manifests/pypi/bluepyopt_setup.py",
"start_line": 9,
"end_line": 20,
"matched_length": 106,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "lgpl-3.0",
"rule_identifier": "lgpl-3.0_276.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl-3.0_276.RULE",
"matched_text": null
}
]
},
{
"identifier": "lgpl_3_0-2db87bcf-56b4-9d7d-7075-2effae31c631",
"license_expression": "lgpl-3.0",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 100.0,
"from_file": "manifests/pypi/bluepyopt_setup.py",
"start_line": 65,
"end_line": 65,
"matched_length": 2,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "lgpl-3.0",
"rule_identifier": "lgpl-3.0_152.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl-3.0_152.RULE",
"matched_text": null
}
]
},
{
"identifier": "lgpl_3_0-38174920-e8ed-7bda-41ec-94df7380b7d5",
"license_expression": "lgpl-3.0",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 100.0,
"from_file": "manifests/pypi/bluepyopt_setup.py",
"start_line": 1,
"end_line": 1,
"matched_length": 1,
"match_coverage": 100.0,
"matcher": "1-hash",
"license_expression": "lgpl-3.0",
"rule_identifier": "lgpl-3.0_29.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl-3.0_29.RULE",
"matched_text": "LGPLv3"
}
]
},
{
"identifier": "mit-3fce6ea2-8abd-6c6b-3ede-a37af7c6efee",
"license_expression": "mit",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 100.0,
"from_file": "manifests/npm-license-string/package.json",
"start_line": 4,
"end_line": 4,
"matched_length": 2,
"match_coverage": 100.0,
"matcher": "2-aho",
"license_expression": "mit",
"rule_identifier": "mit_30.RULE",
"rule_relevance": 100,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mit_30.RULE",
"matched_text": null
}
]
},
{
"identifier": "mit-a822f434-d61f-f2b1-c792-8b8cb9e7b9bf",
"license_expression": "mit",
"detection_count": 1
"detection_count": 1,
"sample_matches": [
{
"score": 100.0,
"from_file": "manifests/npm-license-string/package.json",
"start_line": 1,
"end_line": 1,
"matched_length": 1,
"match_coverage": 100.0,
"matcher": "1-spdx-id",
"license_expression": "mit",
"rule_identifier": "spdx-license-identifier-mit-5da48780aba670b0860c46d899ed42a0f243ff06",
"rule_relevance": 100,
"rule_url": null,
"matched_text": "MIT"
}
]
}
],
"files": [
Expand Down
Loading

0 comments on commit a1fc5d8

Please sign in to comment.