From 693dbccc9dd5eccf7f72a33239c77ff68d3fd5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 7 Aug 2026 10:07:49 +0800 Subject: [PATCH] Extract the protected name restoration out of the credit parser Co-Authored-By: Claude Opus 5 (1M context) --- .../pop_fem_audit_tools/commands/build_db.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/src/pop_fem_audit_tools/commands/build_db.py b/tools/src/pop_fem_audit_tools/commands/build_db.py index 02c06ea..eccb3d8 100644 --- a/tools/src/pop_fem_audit_tools/commands/build_db.py +++ b/tools/src/pop_fem_audit_tools/commands/build_db.py @@ -472,15 +472,30 @@ class ArtistImporter: token: str for token in ArtistImporter.DELIMITER_PATTERN.split( side): - name: str = token.strip() - placeholder = "" - original: str - for placeholder, original in placeholders.items(): - name = name.replace(placeholder, original) + name: str = ArtistImporter.__restore_protected( + token.strip(), placeholders) if name != "": pairs.append((name, role)) return pairs + @staticmethod + def __restore_protected( + name: str, placeholders: dict[str, str]) -> str: + """Restore the protected artist names in a parsed name. + + :param name: A parsed artist name, possibly containing + placeholders. + :param placeholders: The protected artist names, keyed by + the placeholder standing for each of them. + :return: The name with every placeholder replaced by the + protected artist name it stands for. + """ + placeholder: str + original: str + for placeholder, original in placeholders.items(): + name = name.replace(placeholder, original) + return name + @staticmethod def resolve_artist_identity(name: str) -> tuple[str, str]: """Resolve the dedup key and the stored spelling of a name.