mirror of
https://github.com/lllin000/PaperForge.git
synced 2026-07-22 06:50:53 +00:00
feat: persist machine fulltext hash for initial OCR
This commit is contained in:
parent
1474c061a8
commit
cdf969d85e
2 changed files with 42 additions and 7 deletions
|
|
@ -1988,13 +1988,7 @@ def postprocess_ocr_result(vault: Path, key: str, all_results: list[dict]) -> tu
|
|||
document_structure=doc_structure,
|
||||
reader_payload=reader_payload,
|
||||
)
|
||||
meta = write_render_outputs(
|
||||
render_root=ocr_root / "render",
|
||||
user_fulltext=ocr_root / "fulltext.md",
|
||||
markdown=markdown,
|
||||
meta=meta,
|
||||
rebuild_increment=False,
|
||||
)
|
||||
|
||||
|
||||
# --- Phase 3: OCR health report ---
|
||||
from paperforge.worker.ocr_health import (
|
||||
|
|
@ -2062,6 +2056,13 @@ def postprocess_ocr_result(vault: Path, key: str, all_results: list[dict]) -> tu
|
|||
except ValueError:
|
||||
meta["legacy_images_path"] = str(images_dir)
|
||||
meta["path_map"] = {"structured_truth": "assets/", "legacy_compat": "images/"}
|
||||
meta = write_render_outputs(
|
||||
render_root=ocr_root / "render",
|
||||
user_fulltext=ocr_root / "fulltext.md",
|
||||
markdown=markdown,
|
||||
meta=meta,
|
||||
rebuild_increment=False,
|
||||
)
|
||||
write_json(meta_path, meta)
|
||||
|
||||
fulltext_path = ocr_root / "fulltext.md"
|
||||
|
|
|
|||
34
tests/test_ocr_initial_fulltext_writeback.py
Normal file
34
tests/test_ocr_initial_fulltext_writeback.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def _minimal_results() -> list[dict]:
|
||||
return [{
|
||||
"layoutParsingResults": [{
|
||||
"prunedResult": {
|
||||
"width": 600,
|
||||
"height": 800,
|
||||
"parsing_res_list": [
|
||||
{"block_label": "doc_title", "block_content": "Example", "block_bbox": [0, 0, 100, 20], "block_order": 0},
|
||||
{"block_label": "text", "block_content": "Body", "block_bbox": [0, 40, 100, 80], "block_order": 1},
|
||||
],
|
||||
}
|
||||
}]
|
||||
}]
|
||||
|
||||
|
||||
def test_initial_ocr_persists_machine_hash_without_rebuild_fields(tmp_path: Path, monkeypatch) -> None:
|
||||
from paperforge.worker.ocr import postprocess_ocr_result
|
||||
|
||||
vault = tmp_path
|
||||
key = "K1"
|
||||
paper_root = vault / "System" / "PaperForge" / "ocr" / key
|
||||
(paper_root / "meta.json").parent.mkdir(parents=True, exist_ok=True)
|
||||
(paper_root / "meta.json").write_text('{"source_pdf": ""}', encoding="utf-8")
|
||||
|
||||
postprocess_ocr_result(vault, key, _minimal_results())
|
||||
|
||||
meta = json.loads((paper_root / "meta.json").read_text(encoding="utf-8"))
|
||||
assert meta["machine_fulltext_hash"].startswith("sha256:")
|
||||
assert "rebuild_finished_at" not in meta or not meta["rebuild_finished_at"]
|
||||
assert int(meta.get("rebuild_count") or 0) == 0
|
||||
Loading…
Reference in a new issue