Return a Rule object from a ``license_match_mapping`` mapping of LicenseMatch data.
(license_match_mapping)
| 2545 | |
| 2546 | @staticmethod |
| 2547 | def from_match_data(license_match_mapping): |
| 2548 | """ |
| 2549 | Return a Rule object from a ``license_match_mapping`` mapping of |
| 2550 | LicenseMatch data. |
| 2551 | """ |
| 2552 | rule_identifier = license_match_mapping["rule_identifier"] |
| 2553 | |
| 2554 | rule_subclass_by_identifier_prefix = { |
| 2555 | "spdx-license-identifier": SpdxRule, |
| 2556 | "license-detection-unknown": UnknownRule, |
| 2557 | "package-manifest": UnDetectedRule, |
| 2558 | } |
| 2559 | |
| 2560 | prefixes = tuple(rule_subclass_by_identifier_prefix.keys()) |
| 2561 | if rule_identifier.startswith(prefixes): |
| 2562 | for prefix, klass in rule_subclass_by_identifier_prefix.items(): |
| 2563 | if rule_identifier.startswith(prefix): |
| 2564 | return klass( |
| 2565 | license_expression=license_match_mapping["license_expression"], |
| 2566 | text=license_match_mapping.get("matched_text", None), |
| 2567 | length=license_match_mapping["matched_length"], |
| 2568 | ) |
| 2569 | else: |
| 2570 | from licensedcode.cache import get_index |
| 2571 | return get_index().rules_by_id[rule_identifier] |
| 2572 | |
| 2573 | |
| 2574 | def compute_relevance(length): |
no test coverage detected