# Copyright 2026 AutomatosX # SPDX-License-Identifier: AGPL-3.0-only # Modified 2026-10-19 for v1.3; prior component notices are in NOTICE. """Canonical 11-class layout taxonomy.""" from __future__ import annotations from ax_doclayout.errors import TaxonomyError TAXONOMY_ID = "ax-doclayout-11/1" RESERVED_ID = 0 CLASS_NAMES: dict[int, str] = { 1: "caption", 2: "footnote", 3: "formula", 4: "list_item", 5: "page_footer", 6: "page_header", 7: "picture", 8: "section_header", 9: "table", 10: "text", 11: "title", } NAME_TO_ID: dict[str, int] = {name: class_id for class_id, name in CLASS_NAMES.items()} def public_name(class_id: int) -> str: if class_id == RESERVED_ID: raise TaxonomyError("class_id_reserved") try: return CLASS_NAMES[class_id] except KeyError as exc: raise TaxonomyError("class_id_unknown") from exc def public_id(class_name: str) -> int: try: return NAME_TO_ID[class_name] except KeyError as exc: raise TaxonomyError("class_name_unknown") from exc def to_internal(class_id: int) -> int: """Map public 1–11 to zero-based indices 0–10.""" if class_id not in CLASS_NAMES: raise TaxonomyError("class_id_unknown") return class_id - 1 def from_internal(index: int) -> int: class_id = index + 1 if class_id not in CLASS_NAMES: raise TaxonomyError("class_id_unknown") return class_id