호환 동치
동일한 추상적 내용을 가지지만 외관이 다를 수 있는 두 문자 시퀀스. 정규 동치보다 더 넓은 개념. 예: fi ≈ fi, ² ≈ 2.
What Is Compatibility Equivalence?
Two Unicode strings are compatibility equivalent if they represent semantically similar content but may differ in appearance or formatting. Compatibility equivalence is weaker than canonical equivalence: canonically equivalent strings are always compatibility equivalent, but not vice versa.
Common compatibility equivalences include:
- The ligature fi (U+FB01, fi LIGATURE) ≈ fi (f + i separately)
- The superscript ² (U+00B2) ≈ 2 (U+0032)
- The fullwidth A (U+FF21) ≈ A (U+0041)
- The fraction ½ (U+00BD) in NFKD → 1 ⁄ 2 (sequence of three characters)
- The circled digit ① (U+2460) ≈ 1 (U+0031)
Compatibility Normalization Forms
| Form | Description |
|---|---|
| NFKD | Apply compatibility decomposition; apply canonical ordering |
| NFKC | Apply NFKD, then canonically compose |
import unicodedata
examples = [
("\uFB01", "fi ligature"), # fi
("\u00B2", "superscript 2"), # ²
("\uFF21", "fullwidth A"), # A
("\u2460", "circled digit 1"), # ①
("\u00BD", "vulgar fraction 1/2"), # ½
]
for char, label in examples:
nfc = unicodedata.normalize("NFC", char)
nfkc = unicodedata.normalize("NFKC", char)
nfd = unicodedata.normalize("NFD", char)
nfkd = unicodedata.normalize("NFKD", char)
print(f" {char} ({label})")
print(f" NFC len={len(nfc)} NFKC={nfkc!r} len={len(nfkc)}")
print(f" NFD len={len(nfd)} NFKD={[f'U+{ord(c):04X}' for c in nfkd]}")
# fi NFC len=1 NFKC='fi' len=2
# ² NFC len=1 NFKC='2' len=1
# A NFC len=1 NFKC='A' len=1
# ① NFC len=1 NFKC='1' len=1
When to Use NFKC vs NFC
Use NFC when you want to preserve formatting distinctions: a superscript 2 and a plain 2 are different in a math formula. Use NFKC when you want semantic comparison, ignoring presentational variants: a search engine should return results for "fi" when the user types "file". Python uses NFKC for identifier normalization (PEP 3131), so file and file are the same identifier in Python 3.
Caution: NFKC is lossy. Applying it to 2² produces 22, discarding the superscript meaning. Never apply NFKC to content where formatting carries semantic information.
Quick Facts
| Property | Value |
|---|---|
| Concept | Compatibility equivalence |
| Normalization forms | NFKD, NFKC |
| Python function | unicodedata.normalize("NFKC", s) / "NFKD" |
| Lossy? | Yes — formatting distinctions are discarded |
| Python identifier normalization | NFKC (PEP 3131) |
| Search engine use | NFKC for case-folded token normalization |
| Spec reference | Unicode Standard Annex #15 (UAX #15) |
관련 용어
속성의 더 많은 용어
Unicode property (UAX#11) classifying characters as Narrow, Wide, Fullwidth, Halfwidth, Ambiguous, or …
Unicode property controlling how Arabic and Syriac characters connect to adjacent characters. …
Unicode property listing all scripts that use a character, broader than the …
정규 분해 과정에서 결합 기호의 순서를 제어하는 수치 값(0~254)으로, 어떤 결합 기호를 …
마침표, 쉼표, 대시, 따옴표 등 문어를 구성하고 명료하게 하는 데 사용되는 문자. …
지원하지 않는 프로세스에서 눈에 보이는 효과 없이 무시할 수 있는 문자로, 이형 …
문자가 처음 할당된 유니코드 버전. 시스템 및 소프트웨어 버전 간의 문자 지원 …
문자를 대문자, 소문자, 제목 대문자로 변환하는 규칙. 로케일에 따라 달라질 수 있으며(터키어 …
RTL 문맥에서 글리프를 수평으로 반전해야 하는 문자. 예: ( → ), [ …
문자가 속한 문자 체계(예: 라틴, 키릴, 한자). Unicode 16.0은 168개의 문자 체계를 …