Files
C.E.L_Slide_test2/tests/matching/phase14.py
T
KyeongminandClaude Opus 4.8 b836e79ee1 wip: phase_z2 evidence 파이프라인 + matching 실험(phase2~26) + 프론트 trace 패널 진행분 스냅샷
- src: phase_z2 composition/mapper/pipeline/placement_planner/retry, ai_fallback(prompts/schema/validate), mdx_text_atoms 신규
- Front: PipelineTracePanel 신규, FramePanel/SlideCanvas/Home/designAgentApi 등 갱신 + 테스트 4종 추가
- templates/phase_z2: catalog(component_expansion_registry, node_slot_mapping 신규), frames, families, slide_base 갱신
- tests/matching: phase2~26 매칭 실험 스크립트·리포트·온톨로지 전체 (미커밋 진행분)
- tests: b4_v4 evidence, task5~28.5 시리즈, regression(imp95 baseline) 등 신규 테스트 대량 추가
- docs/reference: MDX 구조 인벤토리, MDX→Frame 구조 계약 문서
- scripts: mdx 계약/parity/coverage/viewport 체크, gitea comment, run sync 유틸
- .gitignore: tmp*.json, chromedriver, .orchestrator, *.pkl, Front_test* 등 임시/스냅샷 제외

미완성 작업의 보존용 스냅샷 커밋 (2026-07-02)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 17:03:42 +09:00

150 lines
5.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Phase 14 — 3개 개선 방법 통합표 (사용자 이미지 포맷)
가로: 하이브리드 / AI-Meta (TAG) / 키워드 전처리
세로: 4개 유닛, 각 셀 Top-3 썸네일
"""
import sys
import json
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from common import load_figma_texts
from extract_units import extract_units
from methods import (
method_kiwi_bm25, method_cross_encoder,
method_distinctive_kiwi, method_ai_meta_for_uid,
)
from phase10 import extract_titles_only_mdx, extract_titles_only_figma, TARGET_UNITS
from phase11 import method_ensemble
ROOT = Path(r"d:\ad-hoc\kei\design_agent")
PREVIEW_DIR = ROOT / "data" / "figma_previews"
def short_id(fid, frame_to_short):
return frame_to_short.get(str(fid), "?")
def main():
units_full = extract_units()
figma_full = load_figma_texts()
figma_titles = extract_titles_only_figma()
mdx_titles = {}
for uid, _, _, fname, mid, sub in TARGET_UNITS:
mdx_titles[uid] = extract_titles_only_mdx(fname, mid, sub)
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()}
# 3개 방법 정의
def m_hybrid(uid):
return method_ensemble(units_full[uid], mdx_titles[uid],
figma_full, figma_titles, alpha=0.7)
def m_ai_meta(uid):
return method_ai_meta_for_uid(uid, figma_full)
def m_keyword_prep(uid):
return method_distinctive_kiwi(units_full[uid], figma_full)
methods = [
("하이브리드 (α=0.7: 0.7 BM25 본문×전체 + 0.3 Cross 제목×제목)", m_hybrid),
("AI-Meta (사전 개념 TAG Jaccard+IDF)", m_ai_meta),
("키워드 전처리 (Distinctive-Kiwi: Kiwi+공통어 제거+IDF)", m_keyword_prep),
]
# 실행
results = {} # {method_name: {uid: top3_list}}
scores_hit = {mname: [] for mname, _ in methods}
for mname, fn in methods:
results[mname] = {}
for uid, _, correct_id, *_ in TARGET_UNITS:
ranked = fn(uid)
top3 = ranked[:3]
results[mname][uid] = top3
top1_sid = frame_to_short.get(str(top3[0][0]), "?") if top3 else "?"
scores_hit[mname].append(top1_sid == correct_id)
# ═══ MD 리포트 ═══
png_rel = "../../data/figma_previews/"
lines = []
lines.append("# Phase 14 — 3개 개선 방법 통합표")
lines.append("")
lines.append("| 방법 | MDX1 팝업(18) | MDX2 2.2(14) | MDX03-1(13) | MDX03-2(29) | 합계 |")
lines.append("|------|---|---|---|---|------|")
for mname, _ in methods:
hits = scores_hit[mname]
marks = ["✓" if h else "✗" for h in hits]
score = sum(hits)
lines.append(f"| {mname} | {marks[0]} | {marks[1]} | {marks[2]} | {marks[3]} | **{score}/4** |")
lines.append("")
# 콘텐츠 × 방법 매트릭스 (사용자 이미지 포맷)
lines.append("## 통합 매트릭스 — 각 셀에 Top-3 썸네일")
lines.append("")
header_cells = ["콘텐츠"] + [m[0] for m in methods]
lines.append("| " + " | ".join(header_cells) + " |")
lines.append("|" + "|".join(["------"] * len(header_cells)) + "|")
for uid, display, correct_id, *_ in TARGET_UNITS:
row = [f"**{display}**<br>(정답 Frame **{correct_id}**)"]
for mname, _ in methods:
top3 = results[mname][uid]
cells_imgs = []
for fid, score in top3:
sid = frame_to_short.get(str(fid), "?")
info = idx_data.get(sid, {})
png = info.get("png", "")
mark = "⭐ " if sid == correct_id else ""
cells_imgs.append(
f"{mark}![{sid}]({png_rel}{png})<br>**{sid}** ({score * 100:.0f}%)"
)
row.append("<br><br>".join(cells_imgs))
lines.append("| " + " | ".join(row) + " |")
lines.append("")
# 유닛별 상세
lines.append("---")
lines.append("")
lines.append("## 유닛별 전략별 Top-3 상세")
lines.append("")
for uid, display, correct_id, *_ in TARGET_UNITS:
lines.append(f"### {display} — 정답 Frame **{correct_id}**")
lines.append("")
lines.append("| 방법 | 1순위 | 2순위 | 3순위 |")
lines.append("|------|-------|-------|-------|")
for mname, _ in methods:
top3 = results[mname][uid]
row = [mname]
for fid, score in top3:
sid = frame_to_short.get(str(fid), "?")
info = idx_data.get(sid, {})
png = info.get("png", "")
title = info.get("title_text", "").strip().replace("\n", " ") or ""
if len(title) > 15:
title = title[:15] + "…"
mark = "⭐ " if sid == correct_id else ""
row.append(
f"{mark}![{sid}]({png_rel}{png})<br>**{sid}** ({score * 100:.0f}%)<br>{title}"
)
while len(row) < 4:
row.append("-")
lines.append("| " + " | ".join(row) + " |")
lines.append("")
out_path = Path(__file__).parent / "MATRIX_PHASE14.md"
out_path.write_text("\n".join(lines), encoding="utf-8")
print(f"완료: {out_path}")
# 콘솔 요약
print()
for mname, _ in methods:
hits = scores_hit[mname]
marks = ["✓" if h else "✗" for h in hits]
print(f" {mname[:55]:55s} {' '.join(marks)} = {sum(hits)}/4")
if __name__ == "__main__":
main()