NFKD (Compatibility Decomposition)
Normalization Form KD: แยกส่วนแบบ compatibility โดยไม่รวมใหม่ เป็นการ normalize ที่เข้มงวดที่สุด สูญเสียข้อมูลการจัดรูปแบบมากที่สุด
NFKD: The Most Aggressive Decomposition
NFKD (Normalization Form KD — Compatibility Decomposition) is the most expansive of the four normalization forms. It applies both canonical decomposition (like NFD) and compatibility decomposition, breaking everything down to its most primitive components without any recomposition.
Where NFD decomposes é → e + combining acute, NFKD does that plus it also decomposes compatibility characters like ligatures, superscripts, and fullwidth variants. The result is the longest possible representation of a string in Unicode.
NFKD vs NFKC: When to Choose Each
Both NFKD and NFKC apply compatibility folding. The difference is the final step: NFKC recomposes canonical sequences back into precomposed characters, while NFKD does not.
import unicodedata
# é as precomposed (U+00E9)
text = "caf\u00e9"
nfkc_result = unicodedata.normalize("NFKC", text)
nfkd_result = unicodedata.normalize("NFKD", text)
print(len(nfkc_result)) # 4 — é recomposed to single code point
print(len(nfkd_result)) # 5 — é left as e + combining acute
# fi ligature
ligature = "find"
print(unicodedata.normalize("NFKC", ligature)) # "find" — 4 chars
print(unicodedata.normalize("NFKD", ligature)) # "find" — 4 chars (fi has no combining marks to add)
# Superscript
sup = "x²"
print(unicodedata.normalize("NFKC", sup)) # "x2" — 2 recomposed
print(unicodedata.normalize("NFKD", sup)) # "x2" — same (2 has no accent to decompose)
Practical Uses of NFKD
Diacritic stripping with compatibility folding: NFKD is the standard starting point when you want to remove accents AND fold compatibility characters:
import unicodedata
def aggressive_normalize(text: str) -> str:
# 1. NFKD: compatibility fold + decompose
nfkd = unicodedata.normalize("NFKD", text)
# 2. Drop all combining marks (accents, etc.)
stripped = "".join(
c for c in nfkd
if unicodedata.category(c) != "Mn"
)
return stripped
print(aggressive_normalize("fiancée")) # fiancee
print(aggressive_normalize("résumé")) # resume
print(aggressive_normalize("naïve²")) # naive2
Database full-text search: Some search systems use NFKD + accent stripping as a pre-processing step to improve recall — a search for "resume" will match "résumé".
Fingerprinting and deduplication: NFKD provides a canonical key for detecting near-duplicate strings that differ only in how they encode the same visual text.
The Information Loss Warning
Like NFKC, NFKD is a lossy transformation. Once you strip superscripts, ligatures, and combining marks, you cannot recover the original. Only use NFKD for derived index keys or search normalization — never as your storage format.
Quick Facts
| Property | Value |
|---|---|
| Full name | Normalization Form Compatibility Decomposition |
| Algorithm | Compatibility decomposition + canonical decomposition + CCC sort |
| Relation to NFKC | NFKD then compose = NFKC |
| String length | Longest of all four forms |
| Python | unicodedata.normalize("NFKD", s) |
| Lossy? | Yes |
| Typical use | Diacritic stripping, aggressive search normalization, deduplication keys |
| Does NOT recompose | Unlike NFKC — all decomposed sequences stay decomposed |
คำศัพท์ที่เกี่ยวข้อง
เพิ่มเติมใน อัลกอริทึม
Mapping characters to a common case form for case-insensitive comparison. More comprehensive …
Rules (UAX#29) for determining where one user-perceived character ends and another begins. …
Normalization Form C: แยกส่วนแล้วรวมใหม่แบบ canonical ได้รูปแบบที่สั้นที่สุด แนะนำสำหรับการจัดเก็บและแลกเปลี่ยนข้อมูล เป็นรูปแบบมาตรฐานของเว็บ
Normalization Form D: แยกส่วนอย่างสมบูรณ์โดยไม่รวมใหม่ ใช้โดยระบบไฟล์ macOS HFS+ é (U+00E9) → e + …
Normalization Form KC: แยกส่วนแบบ compatibility แล้วรวมแบบ canonical รวมอักขระที่มีลักษณะคล้ายกัน (fi→fi, ²→2, Ⅳ→IV) ใช้สำหรับการเปรียบเทียบตัวระบุ
Comparing Unicode strings requires normalization (NFC/NFD) and optionally collation (locale-aware sorting). Binary …
กระบวนการแปลงข้อความ Unicode เป็นรูปแบบ canonical มาตรฐาน มี 4 รูปแบบ: NFC (รวม), NFD (แยก), …
อักขระที่ถูกยกเว้นจากการรวมแบบ canonical (NFC) เพื่อป้องกันการแตกย่อยแบบ non-starter และรับประกันความเสถียรของอัลกอริทึม ระบุไว้ใน CompositionExclusions.txt
อัลกอริธึมสำหรับค้นหาขอบเขตในข้อความ: ขอบเขต grapheme cluster, คำ และประโยค มีความสำคัญสำหรับการเลื่อนเคอร์เซอร์ การเลือกข้อความ และการประมวลผลข้อความ
ตำแหน่งระหว่างคำตามกฎการแบ่งคำของ Unicode ไม่ใช่แค่การแบ่งตามช่องว่าง แต่รองรับ CJK (ไม่มีช่องว่าง) คำย่อ และตัวเลขอย่างถูกต้อง