This commit is contained in:
2026-06-04 17:00:02 +08:00
parent 36fe76a4ab
commit e08d853734
4 changed files with 19 additions and 7 deletions
+14 -2
View File
@@ -3,8 +3,12 @@ import re
from typing import Any
PLACEHOLDER_PATTERN = re.compile(r'<(?:int|float\d*)[^>]*>')
# Only numeric data placeholders are normalized. Decorative Korean placeholders such as <소수1+>
# stay untouched and do not consume a value index.
DATA_PLACEHOLDER_PATTERN = re.compile(r'<(?:int|float\d*)[^>]*>')
DECORATIVE_KOREAN_PLACEHOLDER_PATTERN = re.compile(r'<[가-힣]+\d+\+>')
VALUE_PATTERN = re.compile(r'\{value\d+\}')
SKILL_DETAIL_NORMALIZE_VERSION = 'decorative-korean-placeholder-v1'
def replace_placeholders(template: str) -> str:
@@ -15,7 +19,15 @@ def replace_placeholders(template: str) -> str:
idx += 1
return f'{{value{idx}}}'
return PLACEHOLDER_PATTERN.sub(repl, template)
protected = DECORATIVE_KOREAN_PLACEHOLDER_PATTERN.sub(lambda match: f'@@DDECORATIVE_{len(match.group(0))}_{match.start()}@@', template)
replacements = {
f'@@DDECORATIVE_{len(match.group(0))}_{match.start()}@@': match.group(0)
for match in DECORATIVE_KOREAN_PLACEHOLDER_PATTERN.finditer(template)
}
normalized = DATA_PLACEHOLDER_PATTERN.sub(repl, protected)
for token, placeholder in replacements.items():
normalized = normalized.replace(token, placeholder)
return normalized
def normalize_skill_detail(skill_data: dict[str, Any]) -> dict[str, Any]: