Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,10 +38,13 @@ def apply_name_tags(text: str, names: list, start_index: int = 100) -> tuple[str
|
|
| 38 |
mapping = {}
|
| 39 |
tagged_text = text
|
| 40 |
counter = start_index
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
for name in names:
|
| 42 |
tag = f"{TAG_PREFIX}{counter:03d}"
|
| 43 |
pattern = re.compile(rf'(?<![가-힣A-Za-z0-9]){re.escape(name)}(?![가-힣A-Za-z0-9])')
|
| 44 |
-
|
| 45 |
tagged_text, n = pattern.subn(tag, tagged_text)
|
| 46 |
if n > 0:
|
| 47 |
mapping[tag] = name
|
|
|
|
| 38 |
mapping = {}
|
| 39 |
tagged_text = text
|
| 40 |
counter = start_index
|
| 41 |
+
|
| 42 |
+
# ✅ 긴 이름 우선 정렬
|
| 43 |
+
names = sorted(set(names), key=len, reverse=True)
|
| 44 |
+
|
| 45 |
for name in names:
|
| 46 |
tag = f"{TAG_PREFIX}{counter:03d}"
|
| 47 |
pattern = re.compile(rf'(?<![가-힣A-Za-z0-9]){re.escape(name)}(?![가-힣A-Za-z0-9])')
|
|
|
|
| 48 |
tagged_text, n = pattern.subn(tag, tagged_text)
|
| 49 |
if n > 0:
|
| 50 |
mapping[tag] = name
|