fix: normalize OCR heading newlines and fix single-word heading level

This commit is contained in:
Research Assistant 2026-06-25 16:14:32 +08:00
parent 423927545d
commit 88116cf262
2 changed files with 8 additions and 1 deletions

View file

@ -79,6 +79,11 @@ def _merge_adjacent_headings(rows: list[dict]) -> None:
return 0
return m.group(1).count(".") + 1
# Normalize OCR line breaks within paragraph_title blocks
for row in rows:
if row.get("raw_label") == "paragraph_title":
row["text"] = (row.get("text") or "").replace("\n", " ")
def _case_style(b: dict) -> str:
t = str(b.get("text", "") or "")
if not t:

View file

@ -461,7 +461,9 @@ def _infer_heading_level(
sentence_verbs = {" is ", " are ", " was ", " were ", " have ", " has ", " been "}
has_sentence_verb = any(v in text.lower() for v in sentence_verbs)
word_count = len(text.split())
if is_mostly_upper and word_count >= 1 and not has_sentence_verb:
# ponytail: all-caps single-word headings (e.g. "MCUb", "EMRE") are
# sub-subsection headings, not top-level section headings
if is_mostly_upper and word_count >= 2 and not has_sentence_verb:
return "section_heading"
if word_count >= 2 and not has_sentence_verb:
return "subsection_heading"