"""두 하이브리드 비교: 구조→BM25 (기존) vs BM25→구조 (역방향)""" import sys import json from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) from common import load_ground_truth, load_figma_texts from extract_units import extract_units from methods import method_hard_filter, method_bm25_then_struct ROOT = Path(r"d:\ad-hoc\kei\design_agent") PREVIEW_DIR = ROOT / "data" / "figma_previews" def main(): gt_list = load_ground_truth() figma = load_figma_texts() units = extract_units() with open(PREVIEW_DIR / "index.json", encoding="utf-8") as f: idx_data = json.load(f) frame_to_short = {info["frame_id"]: sid for sid, info in idx_data.items()} # 7개 중목차 섹션만 (GT 있는 것) gt_by_id = {g["id"]: g for g in gt_list} print(f"{'섹션':15s} {'GT':5s} {'구조→BM25':15s} {'BM25→구조':15s}") print("-" * 65) hard_filter_hits = 0 reversed_hits = 0 total_clear = 0 for g in gt_list: sid = g["id"] if sid not in units: continue text = units[sid] gt_short = frame_to_short.get(str(g["primary"]), "null") if g["primary"] else "null" hf = method_hard_filter(text, figma) rv = method_bm25_then_struct(text, figma) hf_top = frame_to_short.get(str(hf[0][0]), "?") rv_top = frame_to_short.get(str(rv[0][0]), "?") hf_mark = "✅" if hf_top == gt_short else ("·" if gt_short == "null" else "✗") rv_mark = "✅" if rv_top == gt_short else ("·" if gt_short == "null" else "✗") print(f"{sid:15s} {gt_short:5s} {hf_mark} {hf_top:3s} ({hf[0][1]:.1f}) {rv_mark} {rv_top:3s} ({rv[0][1]:.2f})") if g["primary"] is not None: total_clear += 1 if hf_top == gt_short: hard_filter_hits += 1 if rv_top == gt_short: reversed_hits += 1 print() print(f"기존 (구조→BM25) Hit@1: {hard_filter_hits}/{total_clear}") print(f"역방향 (BM25→구조) Hit@1: {reversed_hits}/{total_clear}") if __name__ == "__main__": main()