Created
April 6, 2018 17:21
-
-
Save santhoshtr/e4bb7d8bb952ee5d4cc43b1f0b4d9b38 to your computer and use it in GitHub Desktop.
ICU based string comparison using various collation strengths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from icu import Locale, Collator as ICUCollator | |
import locale | |
collator = ICUCollator.createInstance(Locale("ml_IN")) | |
word1="അവൻ" | |
word2="അവന്\u200d" # "അവന്" | |
collator.setStrength(ICUCollator.PRIMARY); | |
print("[ICU] Are they primary equal? ", collator.compare(word1, word2)) | |
collator.setStrength(ICUCollator.SECONDARY); | |
print("[ICU] Are they secondary equal? ", collator.compare(word1, word2)) | |
collator.setStrength(ICUCollator.TERTIARY); | |
print("[ICU] Are they tertiary equal? ", collator.compare(word1, word2)) | |
locale.setlocale(locale.LC_ALL, "ml_IN.UTF-8") | |
print("[GLIBC] Are they equal? ", locale.strcoll(word1, word2)) |
Basically this says that the word with atomic chillu and zwj based chillu are different only at tertiary level.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output