Files
C.E.L_Slide_test2/tests/matching/phase2.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

133 lines
4.7 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 2: 7개 방법 통합 매트릭스 (3 카테고리)
- 키워드 (3): TF-IDF, Char n-gram, Kiwi+BM25
- 구조 (1): 구조 메타데이터
- 의미 (3): Sentence-BERT 문장 / 단어평균 / IDF가중"""
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_tfidf, method_char_ngram, method_kiwi_bm25,
method_structural,
method_sbert_sentence, method_sbert_summary, method_sbert_chunk,
)
ROOT = Path(r"d:\ad-hoc\kei\design_agent")
PREVIEW_DIR = ROOT / "data" / "figma_previews"
UNIT_ORDER = [
("MDX01-intro", "중목차 앞 본문"),
("MDX01-intro-details", "팝업"),
("MDX01-1", "중목차"),
("MDX01-2", "중목차"),
("MDX01-2-image", "이미지"),
("MDX01-2-details", "팝업+표"),
("MDX02-1", "중목차"),
("MDX02-1-image", "이미지"),
("MDX02-2", "중목차(컨테이너)"),
("MDX02-2.1", "소목차"),
("MDX02-2.2", "소목차"),
("MDX02-2.2-table", "표"),
("MDX03-1", "중목차"),
("MDX03-2", "중목차(컨테이너)"),
("MDX03-2.1", "소목차"),
("MDX03-2.1-table", "표"),
("MDX03-2.2", "소목차"),
]
def fmt_score(score, method_name):
if method_name in ("TF-IDF", "Char-ngram", "Structural",
"SBERT-원본", "SBERT-축약", "SBERT-청크"):
return f"{score * 100:.0f}%"
else:
return f"{score:.1f}"
def main():
units = extract_units()
figma = load_figma_texts()
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개 방법
methods_def = [
("TF-IDF", method_tfidf),
("Char-ngram", method_char_ngram),
("Kiwi+BM25", method_kiwi_bm25),
("Structural", method_structural),
("SBERT-원본", method_sbert_sentence),
("SBERT-축약", method_sbert_summary),
("SBERT-청크", method_sbert_chunk),
]
print("[Phase 2] 7개 방법 × 17 유닛 실행 시작...")
results = {}
for i, (uid, unit_text) in enumerate(units.items(), 1):
print(f" [{i}/{len(units)}] {uid}")
results[uid] = {}
for mname, fn in methods_def:
if not unit_text.strip():
results[uid][mname] = []
continue
try:
ranked = fn(unit_text, figma)
results[uid][mname] = ranked[:3]
except Exception as e:
print(f" ERROR {mname}: {e}")
results[uid][mname] = []
# 리포트
png_rel = "../../data/figma_previews/"
lines = []
lines.append("# Phase 2 — 7개 방법 매트릭스")
lines.append("")
lines.append("3 카테고리 비교: **키워드 매칭 (3) + 구조 매칭 (1) + 의미 매칭 (3)**")
lines.append("")
lines.append("의미 매칭 3가지 — 같은 모델(ko-sroberta, 420MB) × 다른 전략:")
lines.append("- **SBERT-원본**: 전체 텍스트를 한 벡터로 (그대로)")
lines.append("- **SBERT-축약**: 제목+볼드 라벨만 뽑아서 짧게 축약 후 임베딩")
lines.append("- **SBERT-청크**: 블릿/섹션 단위로 쪼개 각 chunk별 최대 유사도 평균")
lines.append("")
for i, (uid, kind) in enumerate(UNIT_ORDER, 1):
lines.append(f"---")
lines.append("")
lines.append(f"## {i}. {uid} ({kind})")
lines.append("")
lines.append("| 방법 | 1순위 | 2순위 | 3순위 |")
lines.append("|------|-------|-------|-------|")
for mname, _ in methods_def:
cells = [mname]
top3 = results[uid].get(mname, [])
if not top3:
cells += ["-", "-", "-"]
else:
for fid, score in top3:
short = frame_to_short.get(str(fid), "?")
info = idx_data.get(short, {})
png_file = info.get("png", "")
title = info.get("title_text", "").strip().replace("\n", " ") or ""
if len(title) > 15:
title = title[:15] + "…"
cell = f"![{short}]({png_rel}{png_file})<br>**{short}** ({fmt_score(score, mname)})<br>{title}"
cells.append(cell)
while len(cells) < 4:
cells.append("-")
lines.append("| " + " | ".join(cells) + " |")
lines.append("")
out_path = Path(__file__).parent / "MATRIX_PHASE2.md"
out_path.write_text("\n".join(lines), encoding="utf-8")
print(f"\n완료: {out_path}")
if __name__ == "__main__":
main()