ontocast.config.section_labels¶
Load versioned section-label schemas from YAML in this package.
Classes¶
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
¶
heading_patterns = Field(default_factory=list)
class-attribute
instance-attribute
¶
id
instance-attribute
¶
keywords = Field(default_factory=list)
class-attribute
instance-attribute
¶
order = Field(default=None, description='Canonical position of this section in a well-formed document of this type. Used only to refuse label fills that would run backwards; absent means the label is not order-constrained.')
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
¶
default_exclude = Field(default_factory=list, description='Label ids dropped by default before extraction (boilerplate sections); overridden by an explicit exclude_sections request option ([] disables exclusion entirely).')
class-attribute
instance-attribute
¶
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
¶
ordered = Field(default=False, description="Whether this document type has a canonical section order, making the per-label 'order' values meaningful for fill guarding.")
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()
¶
label_order(label, schema)
¶
Canonical position of a label in this schema, when order-constrained.
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.
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_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.
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.