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>
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
"""IDF가 높은 (희귀) 키워드 계산 — MDX03 쿼리와 Top-3 프레임의 실제 매칭 희귀 단어 추출"""
|
||||
import sys
|
||||
import math
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from common import load_figma_texts, tokenize_simple
|
||||
from extract_units import extract_units
|
||||
|
||||
|
||||
def main():
|
||||
figma = load_figma_texts()
|
||||
units = extract_units()
|
||||
|
||||
# 전체 corpus: 모든 MDX 유닛 + 모든 Figma 프레임
|
||||
all_docs = {}
|
||||
for uid, text in units.items():
|
||||
all_docs[f"MDX:{uid}"] = tokenize_simple(text)
|
||||
for fid, text in figma.items():
|
||||
all_docs[f"FIG:{fid}"] = tokenize_simple(text)
|
||||
|
||||
# IDF 계산
|
||||
df = Counter()
|
||||
for toks in all_docs.values():
|
||||
for w in set(toks):
|
||||
df[w] += 1
|
||||
N = len(all_docs)
|
||||
idf = {w: math.log(N / c) for w, c in df.items()}
|
||||
|
||||
# IDF 내림차순 정렬 (희귀할수록 위)
|
||||
sorted_idf = sorted(idf.items(), key=lambda x: -x[1])
|
||||
|
||||
print(f"전체 문서 수: {N}")
|
||||
print(f"전체 유니크 토큰: {len(idf)}")
|
||||
print()
|
||||
print("=== 흔한 단어 TOP 20 (IDF 낮음 = 거의 모든 문서에 등장) ===")
|
||||
for w, sc in sorted(idf.items(), key=lambda x: x[1])[:20]:
|
||||
print(f" {w:20s} IDF={sc:.2f} (등장 문서 수={df[w]}/{N})")
|
||||
|
||||
print()
|
||||
print("=== 희귀 단어 TOP 30 (IDF 높음) ===")
|
||||
for w, sc in sorted_idf[:30]:
|
||||
print(f" {w:20s} IDF={sc:.2f} (등장 문서 수={df[w]}/{N})")
|
||||
|
||||
# MDX03-1 쿼리에서 희귀 단어 뽑기
|
||||
print()
|
||||
print("═══════════════════════════════════════")
|
||||
print("MDX03-1 쿼리의 단어별 IDF (높은 순):")
|
||||
print("═══════════════════════════════════════")
|
||||
mdx03_1_tokens = tokenize_simple(units["MDX03-1"])
|
||||
unique_in_query = set(mdx03_1_tokens)
|
||||
ranked = sorted(
|
||||
[(w, idf[w], df[w]) for w in unique_in_query if w in idf],
|
||||
key=lambda x: -x[1]
|
||||
)
|
||||
for w, sc, cnt in ranked[:20]:
|
||||
print(f" {w:20s} IDF={sc:.2f} (등장 문서 수={cnt}/{N})")
|
||||
|
||||
# Frame 15 (정책목표) vs Frame 13 (필수조건) vs Frame 20 (DX S/W 필수)
|
||||
targets = {
|
||||
"Frame 13 (필수조건)": "1171281190",
|
||||
"Frame 15 (정책목표)": "1171281192",
|
||||
"Frame 20 (DX S/W 필수)": "1171281198",
|
||||
}
|
||||
|
||||
print()
|
||||
print("═══════════════════════════════════════")
|
||||
print("MDX03-1 쿼리 ↔ 각 프레임의 공통 희귀 단어 (매칭 기여도 큰 순)")
|
||||
print("═══════════════════════════════════════")
|
||||
for label, fid in targets.items():
|
||||
print(f"\n▶ {label}")
|
||||
if fid not in figma:
|
||||
print(" (프레임 없음)")
|
||||
continue
|
||||
frame_tokens = set(tokenize_simple(figma[fid]))
|
||||
common = unique_in_query & frame_tokens
|
||||
common_ranked = sorted(
|
||||
[(w, idf[w], df[w]) for w in common if w in idf],
|
||||
key=lambda x: -x[1]
|
||||
)
|
||||
for w, sc, cnt in common_ranked[:15]:
|
||||
marker = "⭐" if sc > 2.0 else "·"
|
||||
print(f" {marker} {w:20s} IDF={sc:.2f} ({cnt}문서에 등장)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user