import re


def is_oa_license(license_url):
    """
    This function returns whether we expect a publication under a given license
    to be freely available from the publisher.

    Licenses are as expressed in CrossRef: see https://api.crossref.org/licenses
    """
    if not license_url:
        return False

    license_url = re.sub(r'^http://', 'https://', license_url)

    # straight from dissemin: https://github.com/dissemin/dissemin/blob/0aa00972eb13a6a59e1bc04b303cdcab9189406a/backend/crossref.py#L97
    # thanks dissemin!
    # Licenses considered OA, as stored by CrossRef
    oa_licenses = {
        "https://koreanjpathol.org/authors/access.php",
        "https://olabout.wiley.com/WileyCDA/Section/id-815641.html",
        "https://pubs.acs.org/page/policy/authorchoice_ccby_termsofuse.html",
        "https://pubs.acs.org/page/policy/authorchoice_ccbyncnd_termsofuse.html",
        "https://pubs.acs.org/page/policy/authorchoice_termsofuse.html",
        "https://www.elsevier.com/open-access/userlicense/1.0/",
        "https://open.canada.ca/en/open-government-licence-canada",
    }

    if "creativecommons.org/licenses/" in license_url or "creativecommons.org/publicdomain/" in license_url:
        return True

    if license_url in oa_licenses:
        return True

    return False