MCPcopy Create free account
hub / github.com/917Dhj/DeepPaperNote / extract_raw_sections

Function extract_raw_sections

scripts/extract_source_text.py:148–178  ·  view source on GitHub ↗
(page_texts: list[dict[str, Any]])

Source from the content-addressed store, hash-verified

146
147
148def 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
181def section_ids_for_page(sections: list[dict[str, Any]], page_number: int) -> list[str]:

Callers 1

mainFunction · 0.85

Calls 5

clean_pdf_lineFunction · 0.90
stop_section_reasonFunction · 0.90
match_section_headingFunction · 0.90
new_recordFunction · 0.85
finalize_sectionFunction · 0.85

Tested by

no test coverage detected