互換等価
同じ抽象的内容を持つが外観が異なる場合がある2つの文字シーケンス。正規等価より広い概念。例: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バージョン。システムやソフトウェアバージョン間での文字サポートを判断するのに役立ちます。
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 …
文字を大文字・小文字・タイトルケースに変換するルール。ロケール依存の場合があり(トルコ語のI問題)、1対多のマッピングもあります(ß → SS)。
文字が属する文字体系(例:ラテン、キリル、漢字)。Unicode 16.0は168個のスクリプトを定義し、Scriptプロパティはセキュリティと混在スクリプト検出に重要です。
サポートしていないプロセスで目に見える効果なく無視できる文字で、異体字セレクター・ゼロ幅文字・言語タグなどが含まれます。
名前付きの連続したコードポイント範囲(例:基本ラテン = U+0000〜U+007F)。Unicode 16.0は336個のブロックを定義し、すべてのコードポイントはちょうど1つのブロックに属します。
RTLコンテキストでグリフを水平に反転すべき文字。例:( → )、[ → ]、{ → }、« → »。
すべてのコードポイントを30個のカテゴリ(Lu・Ll・Nd・Soなど)の1つに分類する体系で、7つの主要クラス(文字・記号・数字・句読点・記号・区切り・その他)にグループ化されています。