INNER CODE UNIT · Python
chunk
Laurent00TT/PharosRAG · src/chunker/core.py:256
def chunk(self, elements: list[Element], *, doc_id: str, doc_type: str | None = None,
lang: str = "en", doc_meta: dict | None = None, acl: dict | None = None) -> ChunkResult:
budget = self._budget(doc_type)
banners = _banner_texts(elements) # round-2: drop per-page running banners
kept = [e for e in elements
if e.kind not in NOISE_KINDS and _norm(e.text) not in banners]
# reset-aware switch (review F1): bare-integer numbering only promotes to L1 when
# the doc's bare numbers form a monotonic outline. A restart (1..9,1.. = list usage)
# means the numbers are list ordinals, not chapters -> defer to text_level.
bare_seq = []
for el in kept:
txt = (el.text or "").strip()
if not el.text_level or _structural_nonheading(txt):
continue
num = _leading_number(txt)
if num and num[0] == "bare":
bare_seq.append(num[1])