OCR-Viewer #1

Merged
nathan merged 8 commits from OCR-Viewer into main 2026-05-19 22:03:29 +00:00
2 changed files with 10 additions and 8 deletions
Showing only changes of commit 77323821cb - Show all commits

View File

@@ -6,9 +6,11 @@ Outputs a JSON array of position objects.
import re
import json
from html.parser import HTMLParser
from pathlib import Path
INPUT_FILE = r"C:\Users\natha\IdeaProjects\AI-Prototype\Inputs\ocr-output\Calgary-Highlanders_War-Diary_Sep44_olmocr.md"
OUTPUT_FILE = r"C:\Users\natha\IdeaProjects\AI-Prototype\outputs\Calgary-Highlanders_Sep44_positions.json"
_PROJECT_ROOT = Path(__file__).resolve().parent.parent
INPUT_FILE = _PROJECT_ROOT / "Inputs" / "ocr-output" / "Calgary-Highlanders_War-Diary_Sep44_olmocr.md"
OUTPUT_FILE = _PROJECT_ROOT / "outputs" / "Calgary-Highlanders_Sep44_positions.json"
# ── helpers ──────────────────────────────────────────────────────────────────
@@ -671,10 +673,8 @@ def assign_end_of_day(positions: list[dict]) -> list[dict]:
# ── run ───────────────────────────────────────────────────────────────────────
if __name__ == "__main__":
import pathlib
print("Reading source file …")
text = pathlib.Path(INPUT_FILE).read_text(encoding="utf-8")
text = INPUT_FILE.read_text(encoding="utf-8")
print("Extracting positions …")
positions = extract_positions(text)
@@ -691,8 +691,8 @@ if __name__ == "__main__":
print("Assigning end-of-day flags …")
unique = assign_end_of_day(unique)
pathlib.Path(OUTPUT_FILE).parent.mkdir(parents=True, exist_ok=True)
pathlib.Path(OUTPUT_FILE).write_text(
OUTPUT_FILE.parent.mkdir(parents=True, exist_ok=True)
OUTPUT_FILE.write_text(
json.dumps(unique, indent=2, ensure_ascii=False),
encoding="utf-8"
)
@@ -716,6 +716,8 @@ if __name__ == "__main__":

View File

@@ -10,7 +10,7 @@ Requirements:
Poppler must be on PATH (pdftoppm command must work).
Usage:
python ocr_wardiaries.py --input_dir "C:\path\to\pdfs" --output_dir "C:\path\to\output" --api_key "YOUR_KEY"
python ocr_wardiaries.py --input_dir "C:/path/to/pdfs" --output_dir "C:/path/to/output" --api_key "YOUR_KEY"
"""
import argparse