fix(contract): 纯图片扫描 PDF 坐标高亮与 OCR 复核

This commit is contained in:
sophie committed 2026-07-29 08:56:13 +08:00
1 parent ca312ea751
commit ce1fd59f61
21 files changed
+1665 -54

No files matched your search

@@ -1,6 +1,9 @@
"""
backend/app/services/knowledge_cleaning/edkb_adapter.py
文件用途:edkb_system 轻量适配层
用途:把 edkb_system 的清洗产物适配为业务服务可直接使用的文件路径和统计信息。
依赖:edkb_system.controller、文件系统临时目录和导出产物约定。
逻辑:复制源文件到隔离目录执行清洗,再把 Markdown、分块和原始布局等必要产物持久化到目标目录。
"""
from __future__ import annotations
@@ -60,6 +63,15 @@ def _find_generated_chunks_jsonl(output_root: Path) -> Path | None:
return candidates[0]
def _find_generated_raw_layout(output_root: Path) -> Path | None:
"""定位包含 OCR Block 元数据的原始布局产物,供下游复用检测框。"""
candidates = [path for path in output_root.rglob('01_raw_layout.json') if path.is_file()]
if not candidates:
return None
candidates.sort(key=lambda item: len(item.parts))
return candidates[0]
def _count_jsonl_lines(path: Path) -> int:
count = 0
with path.open(encoding='utf-8', errors='ignore') as handle:
@@ -178,6 +190,12 @@ def build_clean_result(source_path: Path, target_dir: Path) -> dict:
_rewrite_preview_markdown_if_needed(preview_path, target_dir)
content = cleaned_path.read_text(encoding='utf-8', errors='ignore')
chunks_file_path, chunks_count = _persist_debug_chunks(output_dir, target_dir)
raw_layout_source = _find_generated_raw_layout(output_dir)
raw_layout_path = None
if raw_layout_source:
raw_layout_target = target_dir / '01_raw_layout.json'
shutil.copy2(raw_layout_source, raw_layout_target)
raw_layout_path = str(raw_layout_target)
return {
'mode': 'edkb_system',
@@ -186,4 +204,5 @@ def build_clean_result(source_path: Path, target_dir: Path) -> dict:
'word_count': len(content.split()),
'chunks_file_path': chunks_file_path,
'chunks_count': chunks_count,
'raw_layout_path': raw_layout_path,
}