MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / to_dict

Method to_dict

src/licensedcode/match.py:797–840  ·  view source on GitHub ↗

Return a "result" scan data built from a LicenseMatch object.

(
        self,
        license_url_template=SCANCODE_LICENSEDB_URL,
        spdx_license_url=SPDX_LICENSE_URL,
        include_text=False,
        license_text_diagnostics=False,
        whole_lines=False,
        file_path=None,
    )

Source from the content-addressed store, hash-verified

795 )).rstrip()
796
797 def to_dict(
798 self,
799 license_url_template=SCANCODE_LICENSEDB_URL,
800 spdx_license_url=SPDX_LICENSE_URL,
801 include_text=False,
802 license_text_diagnostics=False,
803 whole_lines=False,
804 file_path=None,
805 ):
806 """
807 Return a "result" scan data built from a LicenseMatch object.
808 """
809 matched_text = None
810 matched_text_diagnostics = None
811
812 if include_text:
813 if license_text_diagnostics:
814 matched_text_diagnostics = self.matched_text(whole_lines=False, highlight=True)
815
816 if whole_lines:
817 matched_text = self.matched_text(whole_lines=True, highlight=False)
818 else:
819 matched_text = self.matched_text(whole_lines=False, highlight=False)
820
821 result = {}
822
823 result['license_expression'] = self.rule.license_expression
824 result['license_expression_spdx'] = self.rule.spdx_license_expression()
825 result['from_file'] = file_path
826 result['start_line'] = self.start_line
827 result['end_line'] = self.end_line
828 result['matcher'] = self.matcher
829 result['score'] = self.score()
830 result['matched_length'] = self.len()
831 result['match_coverage'] = self.coverage()
832 result['rule_relevance'] = self.rule.relevance
833 result['rule_identifier'] = self.rule.identifier
834 result['rule_url'] = self.rule.rule_url
835
836 if include_text:
837 result['matched_text'] = matched_text
838 if license_text_diagnostics:
839 result['matched_text_diagnostics'] = matched_text_diagnostics
840 return result
841
842 def get_highlighted_text(self, trace=TRACE_HIGHLIGHTED_TEXT):
843 """

Callers

nothing calls this directly

Calls 5

matched_textMethod · 0.95
scoreMethod · 0.95
lenMethod · 0.95
coverageMethod · 0.95

Tested by

no test coverage detected