File size: 2,146 Bytes
cfe406c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264ccc9
 
 
 
cfe406c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264ccc9
cfe406c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""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")