Analyse a list of LicenseMatch objects, and determine if the license detection is correct or it is wrong/partially-correct/false-positive/has extra words or some other detection case.
(license_matches, package_license=False)
| 1758 | |
| 1759 | |
| 1760 | def analyze_detection(license_matches, package_license=False): |
| 1761 | """ |
| 1762 | Analyse a list of LicenseMatch objects, and determine if the license detection |
| 1763 | is correct or it is wrong/partially-correct/false-positive/has extra words or |
| 1764 | some other detection case. |
| 1765 | """ |
| 1766 | if TRACE: |
| 1767 | logger_debug(f'license_matches {license_matches}', f'package_license {package_license}') |
| 1768 | |
| 1769 | if is_undetected_license_matches(license_matches=license_matches): |
| 1770 | return DetectionCategory.UNDETECTED_LICENSE.value |
| 1771 | |
| 1772 | elif has_unknown_intro_before_detection(license_matches=license_matches): |
| 1773 | return DetectionCategory.UNKNOWN_INTRO_BEFORE_DETECTION.value |
| 1774 | |
| 1775 | elif has_references_to_local_files(license_matches=license_matches): |
| 1776 | return DetectionCategory.UNKNOWN_FILE_REFERENCE_LOCAL.value |
| 1777 | |
| 1778 | # Case where the match is a false positive |
| 1779 | # In package license detection this is turned off |
| 1780 | elif not package_license and is_false_positive( |
| 1781 | license_matches=license_matches, |
| 1782 | package_license=package_license, |
| 1783 | ): |
| 1784 | return DetectionCategory.FALSE_POSITVE.value |
| 1785 | |
| 1786 | elif not package_license and has_correct_license_clue_matches( |
| 1787 | license_matches=license_matches |
| 1788 | ): |
| 1789 | return DetectionCategory.LICENSE_CLUES.value |
| 1790 | |
| 1791 | # Case where all matches have `matcher` as `1-hash` or `1-spdx-id` |
| 1792 | elif is_correct_detection_non_unknown(license_matches=license_matches): |
| 1793 | return DetectionCategory.PERFECT_DETECTION.value |
| 1794 | |
| 1795 | # Case where even though the matches have perfect coverage, they have |
| 1796 | # matches with `unknown` rule identifiers |
| 1797 | elif has_unknown_matches(license_matches=license_matches): |
| 1798 | return DetectionCategory.UNKNOWN_MATCH.value |
| 1799 | |
| 1800 | elif not package_license and is_low_quality_matches(license_matches=license_matches): |
| 1801 | return DetectionCategory.LOW_QUALITY_MATCH_FRAGMENTS.value |
| 1802 | |
| 1803 | # Case where at least one of the matches have `match_coverage` |
| 1804 | # below IMPERFECT_MATCH_COVERAGE_THR |
| 1805 | elif is_match_coverage_less_than_threshold( |
| 1806 | license_matches=license_matches, |
| 1807 | threshold=IMPERFECT_MATCH_COVERAGE_THR, |
| 1808 | ): |
| 1809 | return DetectionCategory.IMPERFECT_COVERAGE.value |
| 1810 | |
| 1811 | # Case where at least one of the match have extra words |
| 1812 | elif has_extra_words(license_matches=license_matches): |
| 1813 | return DetectionCategory.EXTRA_WORDS.value |
| 1814 | |
| 1815 | # Cases where Match Coverage is a perfect 100 for all matches |
| 1816 | else: |
| 1817 | return DetectionCategory.PERFECT_DETECTION.value |
no test coverage detected