/** * 한국 주소 (Korean Address) detection. * Heuristic: detects Korean address patterns by structural markers. * Markers: 시, 도, 구, 군, 읍, 면, 동, 리, 로, 길, 번지, 아파트, 층, 호 */ import type { PIIDetection } from "@klawn/shared"; // Korean address structural pattern: // [시/도] [시/군/구]+ [동/읍/면/리/로/길] [번지] [건물/아파트] [동/층/호] // Supports variable admin levels (e.g., 경기도 성남시 분당구 판교로 789번지) const ADDRESS_REGEX = /(?:서울|부산|대구|인천|광주|대전|울산|세종|경기|강원|충북|충남|전북|전남|경북|경남|제주)(?:특별시|광역시|특별자치시|특별자치도|도)?\s?(?:[\uAC00-\uD7A3]+(?:시|군|구|동|읍|면|리|로|길)\s?){1,4}[\uAC00-\uD7A3\d\s\-]*?\d+(?:번지|번)?/g; // Simpler fallback: detect by marker density const MARKERS = ["시 ", "구 ", "동 ", "로 ", "길 ", "번지", "아파트", "층", "호"]; export function detectAddress(text: string): PIIDetection[] { const results: PIIDetection[] = []; let match: RegExpExecArray | null; // Primary: structured regex ADDRESS_REGEX.lastIndex = 0; while ((match = ADDRESS_REGEX.exec(text)) !== null) { results.push({ type: "ADDRESS", value: match[0].trim(), start: match.index, end: match.index + match[0].length, confidence: 0.8, }); } return results; }