()
| 245 | |
| 246 | |
| 247 | def main(): |
| 248 | if len(sys.argv) < 3: |
| 249 | print(f"Usage: {sys.argv[0]} <paper_text.md> <output_dir>", file=sys.stderr) |
| 250 | sys.exit(1) |
| 251 | |
| 252 | paper_path = Path(sys.argv[1]) |
| 253 | output_dir = Path(sys.argv[2]) |
| 254 | |
| 255 | if not paper_path.exists(): |
| 256 | print(f"ERROR: {paper_path} does not exist", file=sys.stderr) |
| 257 | sys.exit(1) |
| 258 | |
| 259 | print(f"Extracting structure from: {paper_path}") |
| 260 | text = paper_path.read_text(encoding="utf-8") |
| 261 | print(f" Total characters: {len(text):,}") |
| 262 | |
| 263 | # Extract sections |
| 264 | print("\n--- Extracting sections ---") |
| 265 | sections = identify_sections(text) |
| 266 | if sections: |
| 267 | save_list_to_dir(sections, output_dir / "sections") |
| 268 | print(f" Found {len(sections)} sections:") |
| 269 | for s in sections: |
| 270 | print(f" - {s['title']} ({len(s['content'])} chars)") |
| 271 | else: |
| 272 | print(" WARNING: No sections detected. The paper text may not have clear headings.") |
| 273 | # Save the entire text as a single section |
| 274 | (output_dir / "sections").mkdir(parents=True, exist_ok=True) |
| 275 | (output_dir / "sections" / "01_full_text.md").write_text(text, encoding="utf-8") |
| 276 | |
| 277 | # Extract algorithms |
| 278 | print("\n--- Extracting algorithm boxes ---") |
| 279 | algorithms = extract_algorithms(text) |
| 280 | if algorithms: |
| 281 | save_list_to_dir(algorithms, output_dir / "algorithms") |
| 282 | print(f" Found {len(algorithms)} algorithms:") |
| 283 | for a in algorithms: |
| 284 | print(f" - {a['title']}") |
| 285 | else: |
| 286 | print(" No algorithm boxes found.") |
| 287 | |
| 288 | # Extract equations |
| 289 | print("\n--- Extracting equations ---") |
| 290 | equations = extract_equations(text) |
| 291 | if equations: |
| 292 | save_list_to_dir(equations, output_dir / "equations", name_key="number") |
| 293 | print(f" Found {len(equations)} numbered equations") |
| 294 | else: |
| 295 | print(" No numbered equations found (may be inline or in non-standard format).") |
| 296 | |
| 297 | # Extract tables |
| 298 | print("\n--- Extracting tables ---") |
| 299 | tables = extract_tables(text) |
| 300 | if tables: |
| 301 | save_list_to_dir(tables, output_dir / "tables", name_key="caption") |
| 302 | print(f" Found {len(tables)} tables:") |
| 303 | for t in tables: |
| 304 | print(f" - {t['caption']}") |
no test coverage detected