ontocast.tool.chunk.density¶
Content-based section classification for regions with no usable heading.
Some documents carry no section headings at all -- publisher "Letter" formats
run the whole body as continuous prose -- so heading analysis leaves the text
unresolved. This module labels such regions from the surface form of the text
itself, in the same style as :mod:ontocast.tool.chunk.bibliography: count
marker features, normalise per kilochar, and require a conservative threshold.
Two tiers, selected by CHUNK_SECTION_DENSITY:
conservative(default) recognises only the two section types with a near-unique surface form: reference lists and acknowledgements. Both are boilerplate that the default exclusions drop anyway, so a miss is cheap and a hit is worth having.aggressiveadditionally guesses at methods/results/introduction. These features do not cleanly separate those sections -- figure references and past-tense passives appear in results and methods and discussion -- so it is off by default. A wrong label is worse than no label here, because the section filters act on it and a mislabeled chunk is silently dropped.
Subject-domain-agnostic, but like the bibliography detector it assumes English/Latin-script prose. The failure mode is a miss, not a misfire.
classify_by_density(text, schema, *, aggressive=False, min_score=0.6, margin=1.5)
¶
Label a text region from content features, or None if unclear.
A label is returned only when the best score clears min_score and
beats the runner-up by a factor of margin. Ambiguity resolves to
None deliberately: an unlabeled chunk is merely unselectable, whereas a
wrongly labeled one is silently dropped or wrongly extracted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Chunk or section text. |
required |
schema
|
SectionLabelSchema
|
Active label schema. |
required |
aggressive
|
bool
|
Include the low-precision feature set. |
False
|
min_score
|
float
|
Absolute floor the winning score must clear. |
0.6
|
margin
|
float
|
Factor by which the winner must beat the runner-up. |
1.5
|
Returns:
| Type | Description |
|---|---|
tuple[str, float] | None
|
|
Source code in ontocast/tool/chunk/density.py
score_section_labels(text, schema, *, aggressive=False)
¶
Score candidate section labels from content features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Chunk or section text. |
required |
schema
|
SectionLabelSchema
|
Active label schema; labels absent from it are never scored. |
required |
aggressive
|
bool
|
Include the low-precision methods/results/introduction features. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping of label to score; higher is stronger. Empty when the text is |
dict[str, float]
|
too short to judge. |