match license by legalcode url
Closed this issue · 5 comments
faroit commented
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
@faroit there are two ways:
- 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
- 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 nexB/scancode-toolkit@c6d42c9
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
@pombredanne thanks for your suggestions. Can you give a working example for 1.
to make that more clear?
pombredanne commented
@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
thats great, sorry for the late response!
pombredanne commented
Glad it helped!