Thai Sort
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
import icu | |
thkey = icu.Collator.createInstance(icu.Locale('th_TH')).getSortKey | |
words = 'ไก่ ไข่ ก ฮา'.split() | |
print(sorted(words, key=thkey)) # ['ก', 'ไก่', 'ไข่', 'ฮา'] |
เขียนใหม่เป็น pure python
def thkey(word):
cv = re.sub('[็-์]', '', word,re.U) # remove tone
cv = re.sub('([เ-ไ])([ก-ฮ])', '\\2\\1', cv,re.U) # switch lead vowel
tone = re.sub('[^็-์]', ' ', word,re.U) # just tone
return cv+tone
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ก่อนจะ run ได้ ต้องลง icu กะ pyicu ก่อน
conda install icu
กับ
pip install pyicu