"""YAML 룰 로더 — prompts/instrument_inference.yaml을 읽고 캐싱.""" from __future__ import annotations import os import yaml from functools import lru_cache _RULES_PATH = os.path.join( os.path.dirname(os.path.abspath(__file__)), "..", "..", "prompts", "instrument_inference.yaml", ) @lru_cache(maxsize=1) def load_rules() -> dict: """YAML 룰 파일 로드 (lru_cache로 1회만 로드).""" with open(_RULES_PATH, "r", encoding="utf-8") as f: return yaml.safe_load(f) def get_measurement(letter: str) -> str | None: """첫 글자 → 측정량 반환.""" return load_rules().get("measurement", {}).get(letter) def get_modifier(letter: str) -> dict | None: """수식어 글자 → role 정보 반환.""" return load_rules().get("modifiers", {}).get(letter) def get_special_prefix(head: str) -> dict | None: """특수 prefix → role 정보 반환.""" return load_rules().get("special_prefixes", {}).get(head) def get_all_measurements() -> dict: """측정량 전체 표 반환 (naming_convention 시트용).""" return load_rules().get("measurement", {}) def get_all_modifiers() -> dict: """수식어 전체 표 반환 (naming_convention 시트용).""" return load_rules().get("modifiers", {}) def get_all_special_prefixes() -> dict: """특수 prefix 전체 표 반환 (naming_convention 시트용).""" return load_rules().get("special_prefixes", {})