mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 10:08:40 +01:00
fix(launchbox): keep marks the script spells with when folding
A mark was dropped whenever it was not alphanumeric, and the accent strip before it removed every mark carrying a combining class. Between them they took the vowel signs and viramas Indic and Thai scripts spell with, so "हिन्दी गेम" folded to "हनदगम" and titles differing only in those marks collided. A mark now only goes when it sits on a Latin letter, which is the case it was meant for. Collisions across the dump are unchanged at 551 of 186505 keys, none differing in their digits, and the PlayStation 2 gain still measures 96.7%. Also build each game's dict once rather than per index write. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,10 +57,22 @@ def fold_title(title: str) -> str:
|
||||
Letters of every script survive. Keeping only ASCII would reduce a title
|
||||
written in one to whatever digits it carries, collapsing "三國立志傳2" and
|
||||
"忍者村大战2" onto the same key.
|
||||
|
||||
A mark only goes when it sits on a Latin letter, where it is an accent the
|
||||
two sides may disagree about ("Astérix" against "Asterix"). Elsewhere it
|
||||
spells the word: Devanagari and Thai build syllables from marks, so dropping
|
||||
them would reduce "हिन्दी" to "हनद" and collide titles that differ.
|
||||
"""
|
||||
decomposed = unicodedata.normalize("NFKD", title.casefold())
|
||||
without_accents = "".join(c for c in decomposed if not unicodedata.combining(c))
|
||||
return "".join(c for c in without_accents if c.isalnum())
|
||||
kept: list[str] = []
|
||||
for char in unicodedata.normalize("NFKD", title.casefold()):
|
||||
if unicodedata.category(char).startswith("M"):
|
||||
if kept and "a" <= kept[-1] <= "z":
|
||||
continue
|
||||
kept.append(char)
|
||||
elif char.isalnum():
|
||||
kept.append(char)
|
||||
|
||||
return "".join(kept)
|
||||
|
||||
|
||||
def file_name_forms(file_name: str) -> list[str]:
|
||||
|
||||
@@ -193,21 +193,23 @@ class UpdateLaunchboxMetadataTask(RemoteFilePullTask):
|
||||
and platform_elem is not None
|
||||
and platform_elem.text
|
||||
):
|
||||
platform_name = platform_elem.text.strip()
|
||||
game = _element_to_dict(elem)
|
||||
|
||||
# Use a unique combination of name and platform as the key
|
||||
await writer.hset(
|
||||
LAUNCHBOX_METADATA_NAME_KEY,
|
||||
f"{name_elem.text.strip().lower()}"
|
||||
f":{platform_elem.text.strip()}",
|
||||
_element_to_dict(elem),
|
||||
f":{platform_name}",
|
||||
game,
|
||||
)
|
||||
|
||||
folded = fold_title(name_elem.text)
|
||||
if folded:
|
||||
await writer.hset(
|
||||
LAUNCHBOX_METADATA_FOLDED_NAME_KEY,
|
||||
f"{folded}"
|
||||
f":{platform_elem.text.strip()}",
|
||||
_element_to_dict(elem),
|
||||
f"{folded}:{platform_name}",
|
||||
game,
|
||||
)
|
||||
|
||||
elif elem.tag == "GameAlternateName":
|
||||
|
||||
@@ -713,6 +713,10 @@ class TestRemoteSourceGetRom:
|
||||
# its digits would collide with every other title numbered alike.
|
||||
("三國立志傳2", "三國立志傳2"),
|
||||
("Зона 51", "зона51"),
|
||||
# Scripts that build syllables from marks keep them; stripping to
|
||||
# alphanumerics alone would spell these titles differently.
|
||||
("हिन्दी गेम", "हिन्दीगेम"),
|
||||
("สนุกเกอร์", "สนุกเกอร์"),
|
||||
# Nothing comparable left, so callers must treat it as no key.
|
||||
(":: -- ::", ""),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user