规范化 unicode 无法按预期工作

Normalize unicode does not work as expected

我目前面临一些特殊字符的不同 unicode 表示形式的问题,尤其是那些带有重音符号或分音符等的问题。我写了一个 python 脚本,它解析多个数据库转储并比较它们之间的值。问题是,在不同的文件中,这些特殊字符的存储方式不同。在一些文件中,这些字符是组合的,在另一些文件中是分解的。因为我希望从转储中提取的字符串始终以组合表示形式出现,所以我尝试添加以下行:

value = unicodedata.normalize("NFC", value)

但是,这仅在某些情况下解决了我的问题。例如,对于变音符号,它按预期工作。尽管如此,像 ë 这样的字符将保留在分解的模式中 (e͏̈).

我发现,COMBINING GRAPHEME JOINER-character(U+034F) 在 e 和分音符之间。这是否正常,或者这可能是我的问题的原因?

有人知道如何处理这个问题吗?

U+034F COMBINING GRAPHEME JOINER 的目的是确保某些序列在 searching/sorting/normalisation 下保持不同。这是正确处理字符和组合标记所必需的,因为它们在某些具有 Unicode 算法的语言中使用。来自 Unicode 标准的 section 23.2(第 805 页):

U+034F combining grapheme joiner (CGJ) is used to affect the collation of adjacent characters for purposes of language-sensitive collation and searching. It is also used to distinguish sequences that would otherwise be canonically equivalent.

...

In turn, this means that insertion of a combining grapheme joiner between two combining marks will prevent normalization from switching the positions of those two combining marks, regardless of their own combining classes.

一般来说,您应该删除一个 CGJ,而不了解它最初插入的原因。