()
| 352 | |
| 353 | |
| 354 | def main() -> None: |
| 355 | args = parser().parse_args() |
| 356 | record = ensure_record(args.input) |
| 357 | record["paper_id"] = args.paper_id or record.get("paper_id") or paper_id_for_record(record) |
| 358 | pdf_path = resolve_pdf_path(record) |
| 359 | if pdf_path is None: |
| 360 | raise SystemExit("extract_source_text.py requires a resolvable local PDF path.") |
| 361 | |
| 362 | raw_sections_output = args.raw_sections_output |
| 363 | if not raw_sections_output and args.output: |
| 364 | raw_sections_output = str( |
| 365 | Path(args.output).with_name( |
| 366 | Path(args.output).stem.replace("_source_manifest", "") + "_raw_sections.jsonl" |
| 367 | ) |
| 368 | ) |
| 369 | |
| 370 | page_texts = extract_page_texts(pdf_path, args.max_pages) |
| 371 | sections = extract_raw_sections(page_texts) |
| 372 | if raw_sections_output: |
| 373 | write_jsonl(sections, raw_sections_output) |
| 374 | if args.full_text_output: |
| 375 | write_full_text_markdown(sections, args.full_text_output, str(record.get("title", ""))) |
| 376 | |
| 377 | manifest = build_manifest( |
| 378 | record=record, |
| 379 | pdf_path=pdf_path, |
| 380 | page_texts=page_texts, |
| 381 | sections=sections, |
| 382 | raw_sections_output=raw_sections_output, |
| 383 | full_text_output=args.full_text_output, |
| 384 | max_pages=args.max_pages, |
| 385 | ) |
| 386 | emit(manifest, args.output) |
| 387 | |
| 388 | |
| 389 | if __name__ == "__main__": |
no test coverage detected