"""생성 결과 정리 — 구매자 발화 하나만 남긴다. ROUGE 는 표면 어휘를 비교하므로 화자 표시·따옴표·코드펜스·이어 쓴 판매자 발화가 섞이면 점수가 떨어진다. """ import re ROLE_PREFIX_RE = re.compile(r"^\s*(?:\[\s*(?:구매자|MD|바이어)\s*\]|(?:구매자|MD|바이어)\s*[::])\s*") CUT_MARKERS = ("[판매자]", "판매자:", "판매자 :", "[진행]") QUOTE_PAIRS = (('"', '"'), ("“", "”"), ("'", "'"), ("‘", "’")) def clean_utterance(text: str) -> str: text = (text or "").strip() if text.startswith("```"): text = text.strip("`").strip() for marker in CUT_MARKERS: idx = text.find(marker) if idx > 0: text = text[:idx] elif idx == 0: text = "" text = ROLE_PREFIX_RE.sub("", text.strip()) text = " ".join(line.strip() for line in text.splitlines() if line.strip()) for left, right in QUOTE_PAIRS: if len(text) >= 2 and text.startswith(left) and text.endswith(right): text = text[1:-1].strip() return text