aboutcode-org / license-expression

Utility library to parse, normalize and compare License expressions for Python using a boolean logic engine. For expressions using SPDX or any other license id scheme.
http://aboutcode.org
Other
56 stars 23 forks source link

match license by legalcode url #54

Closed faroit closed 3 years ago

faroit commented 3 years ago

on some public data providers licenses are given as urls to the legal code... eg. this entry is referring to http://creativecommons.org/licenses/by-nc/4.0/legalcode.

Is there a simple way to use license-expression to match these?

pombredanne commented 3 years ago

@faroit there are two ways:

  1. If you are combining multiple URLs in proper expressions (e.g. combined with AND and OR), then it could make sense to create a collection of license symbols that are URLs. Then they can be parsed alright with license-expression
  2. Otherwise, I would use https://github.com/nexB/scancode-toolkit that does the detection alright for these and more. I even pushed a few more rarer CC URLs used for detection just now https://github.com/nexB/scancode-toolkit/commit/c6d42c92f9bbe9c4745d31fb4f47c1533a7b5c30

Where (as in which piece of code) would you use it so that I can provide some help? Do you have a collection of all the values your have to date?

faroit commented 3 years ago

@pombredanne thanks for your suggestions. Can you give a working example for 1. to make that more clear?

pombredanne commented 3 years ago

@faroit sorry for the late reply! Here would be a way:

>>> from license_expression import LicenseSymbol, Licensing
>>> symbols = [ 
...   LicenseSymbol(key='cc-by-nc-4.0', aliases=['http://creativecommons.org/licenses/by-nc/4.0/legalcode',]),
...   LicenseSymbol(key='cc-by-4.0', aliases=['http://creativecommons.org/licenses/by/4.0/legalcode',]),
... ]
>>> licensing = Licensing(symbols)
>>> expression = 'http://creativecommons.org/licenses/by-nc/4.0/legalcode OR http://creativecommons.org/licenses/by/4.0/legalcode'
>>> licensing.parse(expression)
OR(LicenseSymbol('cc-by-nc-4.0', aliases=('http://creativecommons.org/licenses/by-nc/4.0/legalcode',), is_exception=False), LicenseSymbol('cc-by-4.0', aliases=('http://creativecommons.org/licenses/by/4.0/legalcode',), is_exception=False))
faroit commented 3 years ago

thats great, sorry for the late response!

pombredanne commented 3 years ago

Glad it helped!