Skip to content

ontocast.onto.iri_policy

normalize_namespace_iri(namespace, *, context='auto')

Return a namespace IRI with a deterministic terminal delimiter.

Existing trailing # or / are preserved. When absent, we append # for ontology contexts and / for facts/default contexts.

Source code in ontocast/onto/iri_policy.py
def normalize_namespace_iri(namespace: str, *, context: URIContext = "auto") -> str:
    """Return a namespace IRI with a deterministic terminal delimiter.

    Existing trailing ``#`` or ``/`` are preserved. When absent, we append ``#``
    for ontology contexts and ``/`` for facts/default contexts.
    """
    text = _strip_brackets(namespace)
    if text.endswith("#") or text.endswith("/"):
        return text
    resolved_context = _resolve_context(text, context)
    suffix = "#" if resolved_context == "ontology" else "/"
    return f"{text}{suffix}"