This is the main entry point to match licenses. Return a sequence of LicenseMatch by matching the file at ``location`` or the ``query_string`` string against this index. Only include matches with scores greater or equal to ``min_score``. If ``as_expression`
(
self,
location=None,
query_string=None,
min_score=0,
as_expression=False,
expression_symbols=None,
approximate=True,
unknown_licenses=False,
deadline=sys.maxsize,
_skip_hash_match=False,
**kwargs,
)
| 896 | return matches |
| 897 | |
| 898 | def match( |
| 899 | self, |
| 900 | location=None, |
| 901 | query_string=None, |
| 902 | min_score=0, |
| 903 | as_expression=False, |
| 904 | expression_symbols=None, |
| 905 | approximate=True, |
| 906 | unknown_licenses=False, |
| 907 | deadline=sys.maxsize, |
| 908 | _skip_hash_match=False, |
| 909 | **kwargs, |
| 910 | ): |
| 911 | """ |
| 912 | This is the main entry point to match licenses. |
| 913 | |
| 914 | Return a sequence of LicenseMatch by matching the file at ``location`` or |
| 915 | the ``query_string`` string against this index. Only include matches with |
| 916 | scores greater or equal to ``min_score``. |
| 917 | |
| 918 | If ``as_expression`` is True, treat the whole text as a single SPDX |
| 919 | license expression and use only expression matching. |
| 920 | |
| 921 | Use the ``expression_symbols`` mapping of {lowered key: LicenseSymbol} |
| 922 | if provided. Otherwise use the standard SPDX license symbols mapping. |
| 923 | |
| 924 | If ``approximate`` is True, perform approximate matching as a last |
| 925 | matching step. Otherwise, only do hash, exact and expression matching. |
| 926 | |
| 927 | If ``unknown_licenses`` is True, perform unknown licenses matching after |
| 928 | all regular matching steps. |
| 929 | |
| 930 | ``deadline`` is a time.time() value in seconds by which the processing |
| 931 | should stop and return whatever was matched so far. |
| 932 | |
| 933 | ``_skip_hash_match`` is used only for testing. |
| 934 | """ |
| 935 | assert 0 <= min_score <= 100 |
| 936 | |
| 937 | if not location and not query_string: |
| 938 | return [] |
| 939 | |
| 940 | qry = query.build_query( |
| 941 | location=location, |
| 942 | query_string=query_string, |
| 943 | idx=self, |
| 944 | text_line_threshold=15, |
| 945 | bin_line_threshold=50, |
| 946 | ) |
| 947 | |
| 948 | if TRACE: |
| 949 | logger_debug('Index.match: for:', location, 'query:', qry) |
| 950 | |
| 951 | if not qry: |
| 952 | return [] |
| 953 | |
| 954 | return self.match_query( |
| 955 | qry=qry, |