This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
"""블록 매칭 비교 스크립트.
|
||||
|
||||
기존 tag/item_count 매칭과 새 TF-IDF 매칭을 나란히 비교.
|
||||
"진짜 좋아졌나?"를 판단하기 위한 도구.
|
||||
|
||||
사용법:
|
||||
python scripts/eval_block_matcher.py
|
||||
|
||||
출력:
|
||||
각 MDX의 중목차별로:
|
||||
- legacy 매칭 결과 (기존)
|
||||
- tfidf 매칭 결과 (새)
|
||||
- 일치 여부
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from src.mdx_normalizer import normalize_mdx_content as normalize_mdx
|
||||
from src.pipeline_v2 import match_blocks_for_sections
|
||||
|
||||
|
||||
def evaluate_mdx(mdx_path: Path):
|
||||
"""단일 MDX에 대해 TF-IDF 매칭 결과를 출력."""
|
||||
content = mdx_path.read_text(encoding="utf-8")
|
||||
result = normalize_mdx(content)
|
||||
sections = result.get("sections", [])
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
print(f"MDX: {mdx_path.name}")
|
||||
print(f"{'='*60}")
|
||||
|
||||
v2_results = match_blocks_for_sections(sections)
|
||||
|
||||
for zone_name, info in v2_results.items():
|
||||
path = info["path"]
|
||||
match = info.get("match")
|
||||
sub_titles = info.get("sub_titles", [])
|
||||
candidates = info.get("candidates", [])
|
||||
|
||||
print(f"\n zone: {zone_name}")
|
||||
print(f" sub_titles: {sub_titles}")
|
||||
print(f" path: {path}")
|
||||
|
||||
if match:
|
||||
print(f" ✅ direct-fit: {match['block_id']} (score={match['score']})")
|
||||
else:
|
||||
print(f" → recipe 경로")
|
||||
if candidates:
|
||||
for i, c in enumerate(candidates):
|
||||
print(f" 후보 {i+1}: {c['block_id']} (score={c['score']})")
|
||||
else:
|
||||
print(f" 후보 없음")
|
||||
|
||||
|
||||
def main():
|
||||
mdx_dir = Path("samples/mdx")
|
||||
if not mdx_dir.exists():
|
||||
print(f"MDX 폴더 없음: {mdx_dir}")
|
||||
return
|
||||
|
||||
mdx_files = sorted(mdx_dir.glob("*.mdx"))
|
||||
if not mdx_files:
|
||||
print("MDX 파일 없음")
|
||||
return
|
||||
|
||||
print(f"블록 매칭 평가 ({len(mdx_files)}개 MDX)")
|
||||
print(f"catalog: templates/catalog/blocks.yaml")
|
||||
|
||||
for mdx_path in mdx_files:
|
||||
try:
|
||||
evaluate_mdx(mdx_path)
|
||||
except Exception as e:
|
||||
print(f"\n ❌ {mdx_path.name}: {e}")
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
print("평가 완료")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user