ontocast.tool.chunk.heading_embedding¶
Embedding heading tier: a heading no pattern or keyword named votes for its nearest label.
Each section-like heading left unnamed by the lexical tiers is embedded with the chunker's model and compared with every label's prototypes (the label name and its keywords). It takes the nearest label when that label is close enough and clearly ahead of the runner-up; otherwise it stays unresolved. The vote is weak: it can select a section but never drop one. Paraphrases and translations of a section name ("Closing Thoughts", "Schlussfolgerung") are what it recovers; topical headings sit far from every label and abstain.
It names content sections only. A heading nearest a boilerplate, back-matter or citations label abstains: a weak label of that kind can neither drop nor flag a unit, so it could only mislabel the content under a banner heading ("Access" is near "open access").
Attributes¶
HEADING_MIN_MARGIN = 0.1
module-attribute
¶
HEADING_MIN_SIMILARITY = 0.7
module-attribute
¶
__all__ = ['HEADING_MIN_MARGIN', 'HEADING_MIN_SIMILARITY', 'embed_heading_labels', 'label_prototypes', 'nearest_label']
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions:¶
embed_heading_labels(outline, schema, embed)
¶
Name unresolved section-like headings by their nearest label (mutates in place).
Runs after the lexical tiers and before inheritance, so the headings a tree places under a heading named here inherit its label, weakly and as this tier's vote. A heading whose nearest label is not a content label abstains.
Returns:
| Type | Description |
|---|---|
int
|
How many headings were named. |
Source code in ontocast/tool/chunk/heading_embedding.py
label_prototypes(schema)
¶
(label, text) pairs a heading is compared with: each name and keyword.
Source code in ontocast/tool/chunk/heading_embedding.py
nearest_label(vector, prototypes)
¶
The label nearest vector, or None when none is near and clear.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector
|
list[float]
|
Unit embedding of a heading. |
required |
prototypes
|
list[tuple[str, list[float]]]
|
|
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The nearest label when its similarity reaches |
str | None
|
|
str | None
|
|