(page_texts: list[dict[str, Any]])
| 146 | |
| 147 | |
| 148 | def extract_raw_sections(page_texts: list[dict[str, Any]]) -> list[dict[str, Any]]: |
| 149 | seen: dict[str, int] = {} |
| 150 | sections: list[dict[str, Any]] = [] |
| 151 | current: dict[str, Any] | None = None |
| 152 | |
| 153 | for page in page_texts: |
| 154 | page_number = int(page["page"]) |
| 155 | if current is None: |
| 156 | current = new_record("preamble", "preamble", page_number, seen) |
| 157 | current["page_end"] = page_number |
| 158 | |
| 159 | for raw_line in str(page.get("text", "")).splitlines(): |
| 160 | line = clean_pdf_line(raw_line) |
| 161 | if not line: |
| 162 | continue |
| 163 | stop_reason = stop_section_reason(line, allow_prefix=True) |
| 164 | heading = match_section_heading(line) |
| 165 | if stop_reason or (heading and heading != "stop"): |
| 166 | finalized = finalize_section(current) |
| 167 | if finalized is not None: |
| 168 | sections.append(finalized) |
| 169 | kind = stop_reason or str(heading) |
| 170 | current = new_record(kind, line, page_number, seen) |
| 171 | continue |
| 172 | current.setdefault("_lines", []).append(line) |
| 173 | |
| 174 | if current is not None: |
| 175 | finalized = finalize_section(current) |
| 176 | if finalized is not None: |
| 177 | sections.append(finalized) |
| 178 | return sections |
| 179 | |
| 180 | |
| 181 | def section_ids_for_page(sections: list[dict[str, Any]], page_number: int) -> list[str]: |
no test coverage detected