import re


def compact_id(iri: str) -> str:
    """Compact an OBO identifier into a prefixed identifier."""
    # Parts taken from pronto.parsers.rdfxml._compact_id
    match = re.match("^http://purl.obolibrary.org/obo/([^#_]+)_(.*)$", iri)
    if match is not None:
        return ":".join(match.groups())
    return iri