ontocast.config.section_labels¶
Load versioned section-label schemas from YAML in this package.
SectionLabelDef
¶
Bases: BaseModel
One canonical section label, its heading patterns and recall keywords.
heading_patterns are high-precision anchored regexes. keywords are
the recall tier: whole-word phrases that identify the label inside a
compound or decorated heading ("Results and Discussion", "Experimental
Section") which the anchored patterns cannot match.
Source code in ontocast/config/section_labels/__init__.py
SectionLabelSchema
¶
Bases: BaseModel
Domain-specific section label vocabulary for one document type.
The catalog of schemas is a partition: every document belongs to exactly
one cell, with general as the residual. document_profile is what
makes that partition checkable -- if two profiles could describe the same
document, the cells overlap and one of them is wrong. It is also the text
the content-based detector embeds, so it describes the document type,
unlike description, which describes this schema's headings.
Source code in ontocast/config/section_labels/__init__.py
clear_section_label_caches()
¶
Clear loader caches (for tests).
label_order(label, schema)
¶
Canonical position of a label in this schema, when order-constrained.
Source code in ontocast/config/section_labels/__init__.py
match_heading_keywords(line, schema)
¶
Match a heading by keyword, for compound and non-canonical headings.
The winner is the label whose keyword appears earliest in the heading, so a compound heading resolves to its leading component ("Results and Discussion" is results, "Conclusions and Outlook" is conclusion). Ties on position are broken by the longer keyword, then by schema order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw heading line. |
required |
schema
|
SectionLabelSchema
|
Active section label schema. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, float] | None
|
|
Source code in ontocast/config/section_labels/__init__.py
match_heading_line(line, schema)
¶
Match a heading against the schema's anchored patterns (high precision).
Deliberately exact: this function also gates segment coalescing, where a
fuzzy match on a body first line would join distinct sections. Recall lives
in :func:match_heading_keywords.
Source code in ontocast/config/section_labels/__init__.py
normalise_heading_line(line)
¶
Reduce a raw heading line to its bare section name.
Strips markdown syntax, publisher decoration glyphs, extraction artefacts and section numbering, so that "## ■ REFERENCES" and "2.1 Synthesis of films" reach the matchers as "REFERENCES" and "Synthesis of films".
Source code in ontocast/config/section_labels/__init__.py
normalise_user_section_label(raw, *, schema_id=None)
¶
Map user-supplied section name to a canonical label.
Source code in ontocast/config/section_labels/__init__.py
resolve_heading_label(line, schema)
¶
Resolve a heading to a label via patterns, then keywords.
Returns:
| Type | Description |
|---|---|
tuple[str, float, str] | None
|
|
tuple[str, float, str] | None
|
or |
Source code in ontocast/config/section_labels/__init__.py
resolve_section_schema_id(*, section_schema_id=None, document_type_hint=None)
¶
Pick schema: explicit id, then hint substring match, then manifest default.
Source code in ontocast/config/section_labels/__init__.py
schema_id_from_hint(document_type_hint)
¶
Schema a free-text document-type hint maps to, or None if it maps to none.
Distinct from :func:resolve_section_schema_id, which cannot express "the
caller told us nothing": it returns the manifest default both for an
unmatched hint and for no hint at all. Automatic detection must run in
exactly those cases, so it needs this finer answer.