Datasets:
Download src/rights.py from SlayerLab/polish-dynaword: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/datasets/SlayerLab/polish-dynaword/resolve/main/src/rights.py
- Command line
-
hf download hf://datasets/SlayerLab/polish-dynaword/src/rights.py
-
curl -L -o rights.py https://huggingface.co/datasets/SlayerLab/polish-dynaword/resolve/main/src/rights.py
2.15 kB
| """edm:rights classifier for the Europeana source (mixed per-record rights). | |
| Dynaword principle = openly licensed. Allow only PD / CC0 / CC-BY / CC-BY-SA. | |
| NC/ND are not open; InC / NoC-* / CNE are in-copyright or unclear -> drop. | |
| Wire into build_dynaword.py only for europeana (per-record); other sources keep | |
| their single per-source license. | |
| """ | |
| # ponytail: substring match on the rights URI — finite, well-known statement set | |
| _OPEN = ( | |
| "creativecommons.org/publicdomain/mark", # Public Domain Mark | |
| "creativecommons.org/publicdomain/zero", # CC0 | |
| "creativecommons.org/licenses/by/", # CC-BY | |
| "creativecommons.org/licenses/by-sa/", # CC-BY-SA | |
| ) | |
| def rights_ok(uri: str) -> bool: | |
| u = (uri or "").lower().rstrip("/") + "/" | |
| return any(tag in u for tag in _OPEN) | |
| def spdx(uri: str) -> str: | |
| u = (uri or "").lower() | |
| if "publicdomain/zero" in u: return "CC0-1.0" | |
| # PDM has no SPDX identifier. Use the explicit public-domain label that | |
| # the source gate recognizes, while retaining the original rights URL in | |
| # the record for legal traceability. | |
| if "publicdomain/mark" in u: return "public-domain (PDM-1.0)" | |
| if "/by-sa/" in u: return "CC-BY-SA-4.0" | |
| if "/by/" in u: return "CC-BY-4.0" | |
| return "UNKNOWN" | |
| if __name__ == "__main__": # self-check | |
| assert rights_ok("http://creativecommons.org/licenses/by-sa/4.0/") | |
| assert rights_ok("https://creativecommons.org/publicdomain/mark/1.0/") | |
| assert rights_ok("http://creativecommons.org/publicdomain/zero/1.0/") | |
| assert not rights_ok("http://creativecommons.org/licenses/by-nc/4.0/") | |
| assert not rights_ok("http://creativecommons.org/licenses/by-nd/4.0/") | |
| assert not rights_ok("http://rightsstatements.org/vocab/InC/1.0/") | |
| assert not rights_ok("http://rightsstatements.org/vocab/NoC-OKLR/1.0/") | |
| assert not rights_ok("") | |
| assert spdx("http://creativecommons.org/licenses/by-sa/4.0/") == "CC-BY-SA-4.0" | |
| assert spdx("http://creativecommons.org/publicdomain/zero/1.0/") == "CC0-1.0" | |
| assert spdx("http://creativecommons.org/publicdomain/mark/1.0/") == "public-domain (PDM-1.0)" | |
| print("ok") | |