ontocast.tool.chunk.routing¶
Route each prepared unit before extraction: extract, citations, non-content or skip.
A section label is evidence, not a decision. A unit is dropped only when a
strong label and the unit's content agree, or when the content alone is
conclusive; anything less is extracted. Selecting sections (target_sections)
is the caller's intent and happens earlier, on labels of any strength.
Each unit carries its label's strength, set where the label was assigned
(:mod:ontocast.tool.chunk.assignment): strong for an anchored heading, a
heading inside a strong section by its number or level, or the content itself;
weak otherwise. A weak label may help selection, never a drop.
Rules, first match wins:
- a unit shorter than
CHUNK_MIN_UNIT_CHARSis skipped; - a strong label the request's
exclude_sectionsnames is skipped; - unless
CHUNK_BIBLIOGRAPHY_MODE=domain_facts, a reference list -- by content alone, or by a strong citations-class label the content agrees with -- takes the bibliography route; - with the schema's default exclusions in force (no
exclude_sections, a schema that was chosen rather than fallen back to), a strong boilerplate-class label on text that states no measurement is skipped; - a table of contents or a list of figures or tables, recognised from the content alone, takes the non-content route;
- front/back matter -- a strong non-content-class label, or a heading the schema names as front/back matter, on text that states no measurement, or identifier and licence boilerplate recognised from the content alone -- takes the non-content route. A fallback schema lends no vocabulary;
- everything else is extracted, with a reason saying why a label that might have dropped it did not.
Attributes¶
__all__ = ['RouteReason', 'RoutingDecision', 'UnitRoute', 'route_unit']
module-attribute
¶
Classes¶
RoutableUnit
¶
Bases: Protocol
What routing reads from a unit.
Source code in ontocast/tool/chunk/routing.py
RouteReason
¶
Bases: StrEnum
Why a unit took its route. Values are wire names (run manifest, logs).
Source code in ontocast/onto/enum.py
Attributes¶
BOILERPLATE = 'boilerplate'
class-attribute
instance-attribute
¶
CITATION_LABEL = 'citation_label'
class-attribute
instance-attribute
¶
CITATION_LIST = 'citation_list'
class-attribute
instance-attribute
¶
CONTENT = 'content'
class-attribute
instance-attribute
¶
CONTENTS_LIST = 'contents_list'
class-attribute
instance-attribute
¶
EXCLUDED_BY_REQUEST = 'excluded_by_request'
class-attribute
instance-attribute
¶
EXCLUSION_OVERRIDDEN = 'exclusion_overridden'
class-attribute
instance-attribute
¶
FALLBACK_SCHEMA = 'fallback_schema'
class-attribute
instance-attribute
¶
LABEL_CONTRADICTED = 'label_contradicted'
class-attribute
instance-attribute
¶
NON_CONTENT = 'non_content'
class-attribute
instance-attribute
¶
UNDERSIZED = 'undersized'
class-attribute
instance-attribute
¶
WEAK_LABEL = 'weak_label'
class-attribute
instance-attribute
¶
RoutingDecision
dataclass
¶
A unit's route and the reason for it.
Source code in ontocast/tool/chunk/routing.py
UnitRoute
¶
Bases: StrEnum
What happens to a unit before extraction. Values are wire names.
Source code in ontocast/onto/enum.py
Functions:¶
route_unit(unit, *, schema, schema_fallback, exclude_sections, config, block_kinds=None)
¶
Decide one unit's route from its label, the label's strength and its content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
RoutableUnit
|
A prepared unit. |
required |
schema
|
SectionLabelSchema | None
|
The schema the document was labelled against; |
required |
schema_fallback
|
bool
|
The schema is the manifest default because nothing chose one; its default exclusions do not apply. |
required |
exclude_sections
|
list[str] | None
|
The request's denylist: |
required |
config
|
ChunkConfig
|
Chunk configuration (bibliography and non-content modes, the unit-size floor). |
required |
block_kinds
|
BlockKinds | None
|
Docling block kinds of the document, when it was converted: a caption or formula is never a citation entry. |
None
|
Returns:
| Type | Description |
|---|---|
RoutingDecision
|
The route and its reason. |
Source code in ontocast/tool/chunk/routing.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |