ontocast.config.section_labels¶
Load versioned section-label schemas from YAML in this package.
Classes¶
RouteClass
¶
Bases: StrEnum
What a section of this label holds, for routing before extraction.
content sections are extracted. boilerplate sections are dropped
by default when the label is strong and the text states no measurement.
non_content sections (front or back matter: author blocks, notes,
availability and licence statements) are flagged, or dropped, per
CHUNK_NON_CONTENT_MODE under the same conditions. citations
sections are reference lists, routed by CHUNK_BIBLIOGRAPHY_MODE when
their content agrees. The class never decides a drop on its own.
Source code in ontocast/config/section_labels/__init__.py
SchemaManifestEntry
¶
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
Attributes¶
compiled_keywords
property
¶
description = Field(min_length=1, description='What a section of this type does in the document, by its role rather than its subject: shown to the model that labels the outline.')
class-attribute
instance-attribute
¶
heading_patterns = Field(default_factory=list)
class-attribute
instance-attribute
¶
id
instance-attribute
¶
keywords = Field(default_factory=list)
class-attribute
instance-attribute
¶
model_config = ConfigDict(extra='forbid')
class-attribute
instance-attribute
¶
route_class = RouteClass.CONTENT
class-attribute
instance-attribute
¶
terminal = Field(default=False, description="A flat list with no subsections (a reference list): descriptive headings after it never inherit the label, and a keyword names it only as a whole conjunct of a heading ('Notes and References'), never inside a longer phrase ('Comparison with literature references').")
class-attribute
instance-attribute
¶
SectionLabelManifest
¶
Bases: BaseModel
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
Attributes¶
compiled_patterns
property
¶
description = ''
class-attribute
instance-attribute
¶
document_profile = Field(default='', description='One sentence describing the kind of document this schema covers, written to be true of no other schema in the catalog. Empty means the schema is not a detection candidate.')
class-attribute
instance-attribute
¶
id
instance-attribute
¶
labels
instance-attribute
¶
model_config = ConfigDict(extra='forbid')
class-attribute
instance-attribute
¶
parent = Field(default=None, description='Reserved for a future document-type hierarchy (e.g. a thesis as a sub-type of academic). Unused today: the catalog is flat, and sub-types would blur the cells a flat detector must separate.')
class-attribute
instance-attribute
¶
schema_version
instance-attribute
¶
Functions:¶
all_known_label_ids()
cached
¶
Source code in ontocast/config/section_labels/__init__.py
canonical_labels(schema)
¶
clear_section_label_caches()
¶
Clear loader caches (for tests).
get_default_section_schema()
¶
heading_head(normalised)
¶
The head of a subtitled heading ("Appendix A: Derivation ..." -> "Appendix A").
Returns:
| Type | Description |
|---|---|
str | None
|
The part before the first colon or spaced dash, or |
str | None
|
heading has no subtitle. |
Source code in ontocast/config/section_labels/__init__.py
label_is_terminal(label, schema)
¶
Whether a label names a flat list that no subsection can belong to.
Source code in ontocast/config/section_labels/__init__.py
label_route_class(label, schema)
¶
Route class of a label in this schema; content for unknown labels.
Source code in ontocast/config/section_labels/__init__.py
labels_of_class(schema, route_class)
¶
Label ids of one route class, in schema order.
Source code in ontocast/config/section_labels/__init__.py
load_manifest()
cached
¶
load_section_label_schema(schema_id)
cached
¶
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.
Resolution follows the heading's head noun, in order:
- a terminal label whose keyword is a whole conjunct ("Notes and References" is references); a terminal label matches no other way;
- a keyword ending the head phrase -- the first conjunct cut before its first preposition ("Characterization Results" is results, "Summary of Results" a summary, "Results and Discussion" results);
- any keyword in the head phrase, rightmost first ("Experimental Section" is methods);
- the earliest keyword anywhere in the heading.
Ties go to the longer keyword, then to schema order. English noun-phrase structure is assumed, as the keywords themselves are English.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw heading line. |
required |
schema
|
SectionLabelSchema
|
Active section label schema. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The label, or |
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
match_heading_name(line, schema)
¶
Match a heading that consists of one of a label's keywords and nothing else.
"Author Contributions" is a name of the acknowledgements section, as exactly as an anchored pattern; "Funding Mechanisms" only contains one.
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_llm_label(raw, schema)
¶
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.
A heading that is a keyword and nothing else resolves as a pattern.
Returns:
| Type | Description |
|---|---|
tuple[str, str] | None
|
|
tuple[str, str] | None
|
|
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.