Skip to content

ontocast.onto.section_models

Pydantic models for document outlines and section spans.

DocumentOutline

Bases: BasePydanticModel

Ordered headings detected in a document, with the document length.

Source code in ontocast/onto/section_models.py
class DocumentOutline(BasePydanticModel):
    """Ordered headings detected in a document, with the document length."""

    text_len: int
    nodes: list[HeadingNode] = Field(default_factory=list)

HeadingNode

Bases: BasePydanticModel

One detected heading in the document outline.

Attributes:

Name Type Description
text str

Raw heading line as it appears in the document text.

normalised str

Heading text after decoration/numbering stripping.

start int

Character offset of the heading line itself.

body_start int

Character offset just past the heading line.

level int

Markdown heading depth (1 = top). Docling reports a flat level for PDF conversions, so this is informational only.

sectionlike bool

Whether the heading reads as a generic section name rather than a descriptive subsection title or a document title.

label str | None

Canonical section label, when resolved.

source SectionLabelSource

How label was decided.

confidence float

Confidence in label in [0, 1].

Source code in ontocast/onto/section_models.py
class HeadingNode(BasePydanticModel):
    """One detected heading in the document outline.

    Attributes:
        text: Raw heading line as it appears in the document text.
        normalised: Heading text after decoration/numbering stripping.
        start: Character offset of the heading line itself.
        body_start: Character offset just past the heading line.
        level: Markdown heading depth (1 = top). Docling reports a flat level
            for PDF conversions, so this is informational only.
        sectionlike: Whether the heading reads as a generic section name rather
            than a descriptive subsection title or a document title.
        label: Canonical section label, when resolved.
        source: How ``label`` was decided.
        confidence: Confidence in ``label`` in ``[0, 1]``.
    """

    text: str
    normalised: str
    start: int
    body_start: int
    level: int = 1
    sectionlike: bool = True
    label: str | None = None
    source: SectionLabelSource = SectionLabelSource.OUTLINE_UNRESOLVED
    confidence: float = 0.0

SectionSpan

Bases: BasePydanticModel

Character span of a document section with a normalised label.

label is None for a region whose section type is not (yet) known — for example an unrecognised but section-like heading. Such a span is explicitly unresolved rather than absent, which is what stops a neighbouring label from being smeared across it.

Source code in ontocast/onto/section_models.py
class SectionSpan(BasePydanticModel):
    """Character span of a document section with a normalised label.

    ``label`` is ``None`` for a region whose section type is not (yet) known —
    for example an unrecognised but section-like heading. Such a span is
    explicitly unresolved rather than absent, which is what stops a neighbouring
    label from being smeared across it.
    """

    label: str | None = None
    start: int
    end: int
    source: SectionLabelSource = SectionLabelSource.OUTLINE_UNRESOLVED
    confidence: float = 0.0