ontocast.tool.chunk.sections¶
Document section span detection and overlap-based labeling for chunk prepare.
DocumentOutline
¶
Bases: BasePydanticModel
Ordered headings detected in a document, with the document length.
Source code in ontocast/onto/section_models.py
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 |
confidence |
float
|
Confidence in |
Source code in ontocast/onto/section_models.py
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
build_section_spans_from_labels(text, labeled_headings)
¶
Build section spans from explicit (offset, label) pairs.
Source code in ontocast/tool/chunk/sections.py
detect_section_spans(text, schema=None, *, include_text_headings=False)
¶
Detect document sections and return a partition of the text into spans.
Every heading closes the preceding span, so an unrecognised heading yields an
explicitly unresolved (label=None) span instead of letting the previous
label run on to the next recognised heading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Document text (the markdown export). |
required |
schema
|
SectionLabelSchema | None
|
Section label schema; the manifest default when omitted. |
None
|
include_text_headings
|
bool
|
Enable the plain-text heading heuristic for documents with no markdown heading structure. |
False
|
Returns:
| Type | Description |
|---|---|
list[SectionSpan]
|
Section spans tiling |
Source code in ontocast/tool/chunk/sections.py
document_text_for_section_tagging(doc)
¶
inject_front_matter_spans(spans, text, schema, *, min_gap_chars=80, max_gap_chars=ABSTRACT_FRONT_MATTER_MAX_CHARS)
¶
Label unheaded front matter before the first labeled section as abstract.
Leading unresolved spans (a title block, an unrecognised banner heading) are
skipped when locating the first labeled section, so front matter is still
recovered on documents whose first recognised section is not an IMRaD
opener -- papers that jump straight to Results are common.
Source code in ontocast/tool/chunk/sections.py
label_from_headings(headings, schema)
¶
Return the first schema label matched from the heading breadcrumb (most-specific first).
This uses docling's structural metadata directly — no substring search required — so it is reliable even when the markdown export differs from the hybrid-chunker text.
Source code in ontocast/tool/chunk/sections.py
label_text_from_spans(text, document_text, spans, search_from)
¶
Assign section label via span overlap; return label and next search offset.
Source code in ontocast/tool/chunk/sections.py
resolve_section_label(chunk_text, document_text, spans, search_from=0)
¶
Return section label with max overlap; second value is next search offset.
When the chunk text cannot be located in document_text the cursor is
preserved at search_from (not reset to 0) so that subsequent segments
are not mis-anchored to the start of the document.