-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkanahangul.py
More file actions
2319 lines (1941 loc) · 86.6 KB
/
kanahangul.py
File metadata and controls
2319 lines (1941 loc) · 86.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
from pathlib import Path
import re
def _read_text_source(text: str | None = None, file: str | Path | None = None, *, encoding: str = "utf-8") -> str:
"""Read input from either a text string or a file path.
Exactly one of `text` or `file` should be provided.
"""
if (text is None) == (file is None):
raise ValueError("Provide exactly one of `text` or `file`.")
if file is not None:
return Path(file).read_text(encoding=encoding)
return text or ""
def _write_text_dest(result: str, out_file: str | Path | None = None, *, encoding: str = "utf-8") -> str:
"""Optionally write result to `out_file`. Returns the result string."""
if out_file is not None:
Path(out_file).write_text(result, encoding=encoding)
return result
import copy
# ============================================================
# Kana -> Hangul mapping (BASE)
# ============================================================
kana_to_hangul_base: dict[str, str] = {
# --- Basic vowels (incl. small vowels) ---
"あ": "아", "ア": "아",
"ぁ": "아", "ァ": "아",
"い": "이", "イ": "이",
"ぃ": "이", "ィ": "이",
"う": "우", "ウ": "우",
"ぅ": "우", "ゥ": "우",
"え": "에", "エ": "에",
"ぇ": "에", "ェ": "에",
"お": "오", "オ": "오",
"ぉ": "오", "ォ": "오",
# --- K row ---
"か": "카", "カ": "카",
"き": "키", "キ": "키",
"く": "쿠", "ク": "쿠",
"け": "케", "ケ": "케",
"こ": "코", "コ": "코",
# K + small ya/yu/yo
"きゃ": "캬", "キャ": "캬",
"きゅ": "큐", "キュ": "큐",
"きょ": "쿄", "キョ": "쿄",
# --- S row ---
"さ": "사", "サ": "사",
"し": "시", "シ": "시",
"す": "스", "ス": "스",
"せ": "세", "セ": "세",
"そ": "소", "ソ": "소",
# SH + small ya/yu/yo
"しゃ": "샤", "シャ": "샤",
"しゅ": "슈", "シュ": "슈",
"しょ": "쇼", "ショ": "쇼",
# --- T row ---
"た": "타", "タ": "타",
"ち": "치", "チ": "치",
"つ": "츠", "ツ": "츠",
"て": "테", "テ": "테",
"と": "토", "ト": "토",
# CH + small ya/yu/yo
"ちゃ": "챠", "チャ": "챠",
"ちゅ": "츄", "チュ": "츄",
"ちょ": "쵸", "チョ": "쵸",
# --- N row ---
"な": "나", "ナ": "나",
"に": "니", "ニ": "니",
"ぬ": "누", "ヌ": "누",
"ね": "네", "ネ": "네",
"の": "노", "ノ": "노",
"ん": "ㄴ", "ン": "ㄴ",
# N + small ya/yu/yo
"にゃ": "냐", "ニャ": "냐",
"にゅ": "뉴", "ニュ": "뉴",
"にょ": "뇨", "ニョ": "뇨",
# --- H row ---
"は": "하", "ハ": "하",
"ひ": "히", "ヒ": "히",
"ふ": "후", "フ": "후",
"へ": "헤", "ヘ": "헤",
"ほ": "호", "ホ": "호",
# H + small ya/yu/yo
"ひゃ": "햐", "ヒャ": "햐",
"ひゅ": "휴", "ヒュ": "휴",
"ひょ": "효", "ヒョ": "효",
# --- M row ---
"ま": "마", "マ": "마",
"み": "미", "ミ": "미",
"む": "무", "ム": "무",
"め": "메", "メ": "메",
"も": "모", "モ": "모",
# M + small ya/yu/yo
"みゃ": "먀", "ミャ": "먀",
"みゅ": "뮤", "ミュ": "뮤",
"みょ": "묘", "ミョ": "묘",
# --- Y row ---
"や": "야", "ヤ": "야",
"ゃ": "야", "ャ": "야",
"ゆ": "유", "ユ": "유",
"ゅ": "유", "ュ": "유",
"よ": "요", "ヨ": "요",
"ょ": "요", "ョ": "요",
# --- R row ---
"ら": "라", "ラ": "라",
"り": "리", "リ": "리",
"る": "루", "ル": "루",
"れ": "레", "レ": "레",
"ろ": "로", "ロ": "로",
# R + small ya/yu/yo
"りゃ": "랴", "リャ": "랴",
"りゅ": "류", "リュ": "류",
"りょ": "료", "リョ": "료",
# --- W row & historical ---
"わ": "와", "ワ": "와",
"を": "오", "ヲ": "오",
"ゑ": "웨", "ヱ": "웨",
"ゐ": "위", "ヰ": "위",
# Vu (added)
"ゔ": "부", "ヴ": "부",# --- G row ---
"が": "가", "ガ": "가",
"ぎ": "기", "ギ": "기",
"ぐ": "구", "グ": "구",
"げ": "게", "ゲ": "게",
"ご": "고", "ゴ": "고",
# G + small ya/yu/yo
"ぎゃ": "갸", "ギャ": "갸",
"ぎゅ": "규", "ギュ": "규",
"ぎょ": "교", "ギョ": "교",
# --- Z/J row ---
"ざ": "자", "ザ": "자",
"じ": "지", "ジ": "지",
"ず": "즈", "ズ": "즈",
"ぜ": "제", "ゼ": "제",
"ぞ": "조", "ゾ": "조",
# J + small ya/yu/yo
"じゃ": "쟈", "ジャ": "쟈",
"じゅ": "쥬", "ジュ": "쥬",
"じょ": "죠", "ジョ": "죠",
# --- D row ---
"だ": "다", "ダ": "다",
"ぢ": "지", "ヂ": "지",
"づ": "즈", "ヅ": "즈",
"で": "데", "デ": "데",
"ど": "도", "ド": "도",
# --- B row ---
"ば": "바", "バ": "바",
"び": "비", "ビ": "비",
"ぶ": "부", "ブ": "부",
"べ": "베", "ベ": "베",
"ぼ": "보", "ボ": "보",
# B + small ya/yu/yo
"びゃ": "뱌", "ビャ": "뱌",
"びゅ": "뷰", "ビュ": "뷰",
"びょ": "뵤", "ビョ": "뵤",
# --- P row ---
"ぱ": "파", "パ": "파",
"ぴ": "피", "ピ": "피",
"ぷ": "푸", "プ": "푸",
"ぺ": "페", "ペ": "페",
"ぽ": "포", "ポ": "포",
# P + small ya/yu/yo
"ぴゃ": "퍄", "ピャ": "퍄",
"ぴゅ": "퓨", "ピュ": "퓨",
"ぴょ": "표", "ピョ": "표",
}
# ============================================================
# Ready-made Hangul profile overrides (edit/extend freely)
# Drop this into your script as-is.
# ============================================================
hangul_profile_overrides: dict[str, dict[str, str]] = {
# --------------------------------------------------------
# Base: your original mapping (no overrides)
# --------------------------------------------------------
"default": {},
# --------------------------------------------------------
# Profile: "strict" (keep it conservative / round-trip friendly)
# - stays close to your current outputs
# --------------------------------------------------------
"strict": {
# (intentionally empty; keep base behavior)
},
# --------------------------------------------------------
# Profile: "loanword_kr" (more like common Korean loanword feel)
# Notes:
# - し/シ often still ends up "시" in Korean, but some people prefer
# stronger "씨" to suggest /shi/; here we KEEP "시".
# - つ/ツ is often perceived closer to "츠" than "쓰" for Japanese tsu.
# - ふ/フ sometimes written "후" (default) vs "푸"; keep "후".
# --------------------------------------------------------
"loanword_kr": {
# keep defaults; but you can tune the "fu" feeling if you want:
# "ふ": "후", "フ": "후", # default already
# or:
# "ふ": "푸", "フ": "푸",
},
# --------------------------------------------------------
# Profile: "shi_ssi"
# - force し/シ and sh- combinations to "씨/쌰/쓔/쑈"
# - this emphasizes the stronger frication some learners want
# --------------------------------------------------------
"shi_ssi": {
"し": "씨", "シ": "씨",
"しゃ": "쌰", "シャ": "쌰",
"しゅ": "쓔", "シュ": "쓔",
"しょ": "쑈", "ショ": "쑈",
},
# --------------------------------------------------------
# Profile: "tsu_sseu"
# - make つ/ツ become 쓰 (instead of 츠)
# - useful if you prefer to avoid the "츠" look
# --------------------------------------------------------
"tsu_sseu": {
"つ": "쓰", "ツ": "쓰",
},
# Combine styles as another profile example
"shi_ssi_tsu_sseu": {
"し": "씨", "シ": "씨",
"しゃ": "쌰", "シャ": "쌰",
"しゅ": "쓔", "シュ": "쓔",
"しょ": "쑈", "ショ": "쑈",
"つ": "쓰", "ツ": "쓰",
},
# --------------------------------------------------------
# Profile: "ja_simple"
# - make じゃ/じゅ/じょ map to 자/주/조 (less "foreign-looking")
# - rather than 쟈/쥬/죠
# --------------------------------------------------------
"ja_simple": {
"じゃ": "자", "ジャ": "자",
"じゅ": "주", "ジュ": "주",
"じょ": "조", "ジョ": "조",
},
# --------------------------------------------------------
# Profile: "cha_chya"
# - some prefer ちゃ/チャ to be "차" not "챠"
# - and similarly ちゅ/ちょ
# --------------------------------------------------------
"cha_chya": {
"ちゃ": "차", "チャ": "차",
"ちゅ": "추", "チュ": "추",
"ちょ": "초", "チョ": "초",
},
# --------------------------------------------------------
# Profile: "korean_media"
# - a more "Korean viewer" feel:
# * strong shi -> 씨
# * tsu -> 쓰
# * ja -> 자/주/조
# * optionally cha -> 차/추/초
# --------------------------------------------------------
"korean_media": {
"し": "씨", "シ": "씨",
"しゃ": "쌰", "シャ": "쌰",
"しゅ": "쓔", "シュ": "쓔",
"しょ": "쑈", "ショ": "쑈",
"つ": "쓰", "ツ": "쓰",
"じゃ": "자", "ジャ": "자",
"じゅ": "주", "ジュ": "주",
"じょ": "조", "ジョ": "조",
# Uncomment if you prefer "cha" without the palatalized look:
# "ちゃ": "차", "チャ": "차",
# "ちゅ": "추", "チュ": "추",
# "ちょ": "초", "チョ": "초",
},
# --------------------------------------------------------
# Profile: "my_roundtrip_safe_plus"
# - tiny changes that usually still round-trip well:
# * keep shi as 시 (default)
# * keep tsu as 츠 (default)
# * change only "fu" if desired
# --------------------------------------------------------
"my_roundtrip_safe_plus": {
# You can pick ONE:
# "ふ": "후", "フ": "후", # default
# "ふ": "푸", "フ": "푸", # alternate
},
}
KANA_TO_HANGUL_PROFILES: dict[str, dict[str, str]] = {}
for profile_name, overrides in hangul_profile_overrides.items():
d = copy.deepcopy(kana_to_hangul_base)
d.update(overrides)
KANA_TO_HANGUL_PROFILES[profile_name] = d
# ============================================================
# Hangul <-> Korean Romanization systems (separate from JP romaji)
# ============================================================
#
# This module already includes Japanese kana<->romaji utilities. The following
# section adds Korean Hangul<->Latin romanization utilities that are *system*
# aware (RR, MR, Yale, etc.) using dict-based tables.
#
# Design goal: "round-trip" for text produced by `hangul_to_kroman_text` when
# decoded with `kroman_to_hangul_text`, especially when using a syllable
# separator (default "-") to avoid ambiguity across syllable boundaries.
# System tables are based on the standard consonant/vowel correspondences for:
# - Revised Romanization (RR) (South Korea, 2000)
# - McCune–Reischauer (MR) (1939) and MR-derived variants (incl. NK 1992)
# - Yale romanization (linguistics)
# - ALA-LC (library cataloging; MR-derived)
#
# Note: Full "pronunciation-based" rules (liaison, assimilation, etc.) vary by
# system and context. For reversibility we intentionally implement a *letter-by-letter*
# (syllable-by-syllable) transliteration variant, not a phonological one.
KROMAN_SYSTEMS: dict[str, dict[str, object]] = {
"rr": {
"name": "Revised Romanization of Korean",
"abbr": "RR",
"year": 2000,
"notes": "Syllable-by-syllable reversible variant (no phonological rules).",
"onset": {
"": 11, # ㅇ
"g": 0, "kk": 1, "n": 2, "d": 3, "tt": 4, "r": 5, "m": 6,
"b": 7, "pp": 8, "s": 9, "ss": 10, "j": 12, "jj": 13, "ch": 14,
"k": 15, "t": 16, "p": 17, "h": 18,
},
"vowel": {
"a": 0, "ae": 1, "ya": 2, "yae": 3, "eo": 4, "e": 5, "yeo": 6, "ye": 7,
"o": 8, "wa": 9, "wae": 10, "oe": 11, "yo": 12,
"u": 13, "wo": 14, "we": 15, "wi": 16, "yu": 17,
"eu": 18, "ui": 19, "i": 20,
},
"coda": {
"": 0,
"k": 1, "kk": 2, "ks": 3, "n": 4, "nj": 5, "nh": 6, "t": 7,
"l": 8, "lk": 9, "lm": 10, "lb": 11, "ls": 12, "lt": 13, "lp": 14, "lh": 15,
"m": 16, "p": 17, "ps": 18, "t_s": 19, "t_ss": 20, "ng": 21,
"t_j": 22, "t_ch": 23, "k_kh": 24, "t_th": 25, "p_ph": 26, "t_h": 27,
},
# romanization output tables (index -> string)
"onset_out": ["g","kk","n","d","tt","r","m","b","pp","s","ss","","j","jj","ch","k","t","p","h"],
"vowel_out": ["a","ae","ya","yae","eo","e","yeo","ye","o","wa","wae","oe","yo","u","wo","we","wi","yu","eu","ui","i"],
# RR coda output uses neutralized letters; we keep a reversible variant by using distinct strings
"coda_out": ["","k","kk","ks","n","nj","nh","t","l","lk","lm","lb","ls","lt","lp","lh","m","p","ps","t","t","ng","t","t","k","t","p","t"],
},
"mr": {
"name": "McCune–Reischauer",
"abbr": "MR",
"year": 1939,
"notes": "Reversible transliteration variant; uses diacritics ŏ/ŭ and apostrophes for aspiration.",
"onset": {
"": 11,
"k": 0, "kk": 1, "n": 2, "t": 3, "tt": 4, "r": 5, "m": 6,
"p": 7, "pp": 8, "s": 9, "ss": 10, "ch": 12, "tch": 13, "ch'": 14,
"k'": 15, "t'": 16, "p'": 17, "h": 18,
},
"vowel": {
"a": 0, "ae": 1, "ya": 2, "yae": 3, "ŏ": 4, "e": 5, "yŏ": 6, "ye": 7,
"o": 8, "wa": 9, "wae": 10, "oe": 11, "yo": 12,
"u": 13, "wŏ": 14, "we": 15, "wi": 16, "yu": 17,
"ŭ": 18, "ŭi": 19, "i": 20,
},
"coda": {
"": 0,
"k": 1, "kk": 2, "ks": 3, "n": 4, "nj": 5, "nh": 6, "t": 7,
"l": 8, "lk": 9, "lm": 10, "lb": 11, "ls": 12, "lt": 13, "lp": 14, "lh": 15,
"m": 16, "p": 17, "ps": 18, "t_s": 19, "t_ss": 20, "ng": 21,
"t_j": 22, "t_ch": 23, "k_kh": 24, "t_th": 25, "p_ph": 26, "t_h": 27,
},
"onset_out": ["k","kk","n","t","tt","r","m","p","pp","s","ss","","ch","tch","ch'","k'","t'","p'","h"],
"vowel_out": ["a","ae","ya","yae","ŏ","e","yŏ","ye","o","wa","wae","oe","yo","u","wŏ","we","wi","yu","ŭ","ŭi","i"],
"coda_out": ["","k","k","ks","n","nj","nh","t","l","lk","lm","lb","ls","lt","lp","lh","m","p","ps","t","t","ng","t","t","k","t","p","t"],
},
"yale": {
"name": "Yale romanization of Korean",
"abbr": "Yale",
"year": 1942,
"notes": "Morphophonemic-focused; reversible transliteration variant.",
"onset": {
"": 11,
"k": 0, "kk": 1, "n": 2, "t": 3, "tt": 4, "l": 5, "m": 6,
"p": 7, "pp": 8, "s": 9, "ss": 10, "c": 12, "cc": 13, "ch": 14,
"kh": 15, "th": 16, "ph": 17, "h": 18,
},
# Yale vowel spellings (modern Korean)
"vowel": {
"a": 0, "ay": 1, "ya": 2, "yay": 3, "e": 4, "ey": 5, "ye": 6, "yey": 7,
"o": 8, "wa": 9, "way": 10, "oy": 11, "yo": 12,
"u": 13, "we": 14, "wey": 15, "wuy": 16, "yu": 17,
"u_": 18, "uy": 19, "i": 20,
},
"coda": { # we keep RR-like unique codas for reversibility
"": 0,
"k": 1, "kk": 2, "ks": 3, "n": 4, "nc": 5, "nh": 6, "t": 7,
"l": 8, "lk": 9, "lm": 10, "lp": 11, "ls": 12, "lt": 13, "lp2": 14, "lh": 15,
"m": 16, "p": 17, "ps": 18, "t_s": 19, "ss": 20, "ng": 21,
"c": 22, "ch": 23, "kh": 24, "th": 25, "ph": 26, "h": 27,
},
"onset_out": ["k","kk","n","t","tt","l","m","p","pp","s","ss","","c","cc","ch","kh","th","ph","h"],
# For ㅡ we use "u_" (common ASCII-safe stand-in for Yale's special symbol)
"vowel_out": ["a","ay","ya","yay","e","ey","ye","yey","o","wa","way","oy","yo","u","we","wey","wuy","yu","u_","uy","i"],
"coda_out": ["","k","kk","ks","n","nc","nh","t","l","lk","lm","lp","ls","lt","lp","lh","m","p","ps","t","ss","ng","c","ch","kh","th","ph","h"],
},
# MR-derived variants (kept as aliases for reversible transliteration here)
"nk1992": {
"name": "Romanization of Korean (North Korea)",
"abbr": "NK (1992)",
"year": 1992,
"notes": "Includes an 'official' variant based on MR-derived DPRK rules; reversible variant available.",
# Reversible tables (MR-like with DPRK vowel choices; used for round-trip with syllable_sep)
"onset": {
"": 11,
"k": 0, "kk": 1, "n": 2, "t": 3, "tt": 4, "r": 5, "m": 6,
"p": 7, "pp": 8, "s": 9, "ss": 10, "ch": 12, "tch": 13, "ch'": 14,
"k'": 15, "t'": 16, "p'": 17, "h": 18,
},
"vowel": {
"a": 0, "ae": 1, "ya": 2, "yae": 3, "ŏ": 4, "e": 5, "yŏ": 6, "ye": 7,
"o": 8, "wa": 9, "wae": 10,
# DPRK often uses "oe" for ㅚ (some sources note later preference for "oi");
# reversible variant uses "oe".
"oe": 11,
"yo": 12,
"u": 13, "wŏ": 14, "we": 15, "wi": 16, "yu": 17,
"ŭ": 18, "ŭi": 19, "i": 20,
},
"coda": {
"": 0,
"k": 1, "kk": 2, "ks": 3, "n": 4, "nj": 5, "nh": 6, "t": 7,
"l": 8, "lk": 9, "lm": 10, "lb": 11, "ls": 12, "lt": 13, "lp": 14, "lh": 15,
"m": 16, "p": 17, "ps": 18, "t_s": 19, "t_ss": 20, "ng": 21,
"t_j": 22, "t_ch": 23, "k_kh": 24, "t_th": 25, "p_ph": 26, "t_h": 27,
},
"onset_out": ["k","kk","n","t","tt","r","m","p","pp","s","ss","","ch","tch","ch'","k'","t'","p'","h"],
"vowel_out": ["a","ae","ya","yae","ŏ","e","yŏ","ye","o","wa","wae","oe","yo","u","wŏ","we","wi","yu","ŭ","ŭi","i"],
"coda_out": ["","k","k","ks","n","nj","nh","t","l","lk","lm","lb","ls","lt","lp","lh","m","p","ps","t","t","ng","t","t","k","t","p","t"],
},
"ala-lc": {
"name": "ALA-LC romanization for Korean",
"abbr": "ALA-LC",
"year": 2009,
"notes": "Includes an 'official' variant using letter-position rules from the 2009 table; reversible variant available.",
# Reversible tables (MR-like)
"onset": {
"": 11,
"k": 0, "kk": 1, "n": 2, "t": 3, "tt": 4, "r": 5, "m": 6,
"p": 7, "pp": 8, "s": 9, "ss": 10, "ch": 12, "tch": 13, "ch'": 14,
"k'": 15, "t'": 16, "p'": 17, "h": 18,
},
"vowel": {
"a": 0, "ae": 1, "ya": 2, "yae": 3, "ŏ": 4, "e": 5, "yŏ": 6, "ye": 7,
"o": 8, "wa": 9, "wae": 10, "oe": 11, "yo": 12,
"u": 13, "wŏ": 14, "we": 15, "wi": 16, "yu": 17,
"ŭ": 18, "ŭi": 19, "i": 20,
},
"coda": {
"": 0,
"k": 1, "kk": 2, "ks": 3, "n": 4, "nj": 5, "nh": 6, "t": 7,
"l": 8, "lk": 9, "lm": 10, "lb": 11, "ls": 12, "lt": 13, "lp": 14, "lh": 15,
"m": 16, "p": 17, "ps": 18, "t_s": 19, "t_ss": 20, "ng": 21,
"t_j": 22, "t_ch": 23, "k_kh": 24, "t_th": 25, "p_ph": 26, "t_h": 27,
},
"onset_out": ["k","kk","n","t","tt","r","m","p","pp","s","ss","","ch","tch","ch'","k'","t'","p'","h"],
"vowel_out": ["a","ae","ya","yae","ŏ","e","yŏ","ye","o","wa","wae","oe","yo","u","wŏ","we","wi","yu","ŭ","ŭi","i"],
"coda_out": ["","k","k","ks","n","nj","nh","t","l","lk","lm","lb","ls","lt","lp","lh","m","p","ps","t","t","ng","t","t","k","t","p","t"],
},
}
def _kroman_resolve_system(system: str) -> dict[str, object]:
key = system.strip().lower()
sysd = KROMAN_SYSTEMS.get(key)
if sysd is None:
sysd = KROMAN_SYSTEMS["rr"]
# resolve aliases
if "alias_of" in sysd:
sysd = KROMAN_SYSTEMS[str(sysd["alias_of"])]
return sysd
def _compose_hangul(L: int, V: int, T: int) -> str:
return chr(_HANGUL_BASE + ((L * _NUM_VOWELS + V) * _NUM_TAILS) + T)
# ----------------------------
# Official encoders (ALA-LC 2009/2025 table; DPRK MR-for-DPRK guidance)
# ----------------------------
#
# These implement **letter-position** behavior (context-sensitive) based on:
# - Library of Congress "Korean Romanization Table (2009 version)" (minor layout fixes July 2025)
# Letter Position Rules for Romanization (pp. 64-67 in the PDF). citeturn1view0
# - NGA "ROMANIZATION OF KOREAN - MR for DPRK" guidance tables (2017). citeturn3view0
#
# Important: These are "official-ish" pragmatic implementations. ALA-LC also specifies
# word-division and many dictionary-based pronunciation exceptions; DPRK guidance includes
# large consonant cluster tables. We implement the most impactful *within-word* letter-position
# rules so output looks like the official tables for common cases. For perfect reversibility, use
# variant="reversible" (the dict-based syllable tables).
# Choseong and Jongseong inventories (standard Unicode order)
_CHO = ["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"]
_JONG = ["","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"]
# Vowel sets used in ALA-LC rules
# yotized vowels: ㅑ ㅒ ㅕ ㅖ ㅛ ㅠ (Unicode jungseong indices: 2,3,6,7,12,17)
_VOWELS_YOTIZED = {2, 3, 6, 7, 12, 17}
# 'wi' vowel (ㅟ) index is 16 in Unicode jungseong order
_VOWEL_WI = 16
# ㅣ index is 20
_VOWEL_I = 20
# Helper: detect "word boundary" for official rules
def _is_word_boundary(prev_char: str | None) -> bool:
return prev_char is None or not _is_hangul_syllable(prev_char)
# Word-boundary logic for "official" romanization:
# - boundary_mode="whitespace": boundaries only on whitespace
# - boundary_mode="whitespace_punct": whitespace and most punctuation reset word-initial rules
# - boundary_mode="custom": use `boundary_chars` as the reset set
#
# We avoid treating '.' and ',' as word boundaries when they are between digits (e.g., 3.14, 1,000).
_DEFAULT_PUNCT_RESET = ".,;:!?()[]{}<>\"'“”‘’/\\|·•—–-"
_WHITESPACE = " \\t\\n\\r\\f\\v"
def _boundary_reset_set(boundary_mode: str, boundary_chars: str | None) -> set[str]:
mode = (boundary_mode or "whitespace_punct").lower()
if mode == "whitespace":
return set(_WHITESPACE)
if mode == "custom":
return set(boundary_chars or "")
return set(_WHITESPACE) | set(_DEFAULT_PUNCT_RESET)
def _sep_resets_word(sep_text: str, prev_char: str | None, next_char: str | None, reset_set: set[str]) -> bool:
if any(ch in _WHITESPACE for ch in sep_text):
return True
if sep_text in {".", ","} and (prev_char and prev_char.isdigit()) and (next_char and next_char.isdigit()):
return False
return any(ch in reset_set for ch in sep_text)
def _apply_word_sep_policy(sep_text: str, policy: str) -> str:
"""Normalize separator output.
Policies:
- keep: return original separator text
- space: replace any separator run with single space
- hyphenate: pure-whitespace runs become '-', but mixed punctuation+whitespace keeps punctuation and normalizes whitespace to single spaces
- smart: normalize whitespace to single spaces, keep punctuation/order (retains a space around punctuation if it was there)
- smart_hyphenate: like smart, but pure-whitespace runs become '-'
This avoids smashing things like "대한 (민국)" into "대한(민국)".
"""
policy = (policy or "keep").lower()
if policy == "keep":
return sep_text
# Normalize any whitespace run to a single space (preserving punctuation and order)
norm_ws = re.sub(r"[ \\t\\n\\r\\f\\v]+", " ", sep_text)
# Pure whitespace separator?
is_pure_ws = (norm_ws.strip() == "") and any(ch in _WHITESPACE for ch in sep_text)
if policy == "space":
return " "
if policy == "hyphenate":
return "-" if is_pure_ws else norm_ws
if policy == "smart":
return " " if is_pure_ws else norm_ws
if policy == "smart_hyphenate":
return "-" if is_pure_ws else norm_ws
return sep_text
def _ala_initial_n_r_suppressed(L: int, V: int) -> bool:
# ALA-LC: initial ㄴ, ㄹ not romanized before ㅣ and yotized vowels (Letter Position Rules table). citeturn1view0
return (V == _VOWEL_I) or (V in _VOWELS_YOTIZED)
def _ala_onset(L: int, V: int, prev_T: int | None, prev_is_hangul: bool, prev_T_is_vowel: bool, next_L: int | None) -> str:
"""ALA-LC onset (syllabic initial) with letter-position rules."""
# ㅇ onset: not romanized
if L == _L_IEUNG_INDEX:
return ""
# Word-initial ㄴ / ㄹ suppression
if prev_is_hangul is False:
if L in (2, 5) and _ala_initial_n_r_suppressed(L, V):
return ""
# initial ㄹ -> n before other vowels per table. citeturn1view0
if L == 5:
return "n"
# initial ㄴ -> n (handled above when suppressed)
if L == 2:
return "n"
# other initials: fixed forms (table uses apostrophes for aspiration)
return ["k","kk","n","t","tt","r","m","p","pp","s","ss","","ch","tch","ch'","k'","t'","p'","h"][L]
# Medial onset rules (within a word)
prev_jong = _JONG[prev_T or 0]
prev_coda_jamo = prev_jong
# ㄴ: L when preceded or followed by ㄹ, else n citeturn1view0
if L == 2:
if prev_coda_jamo == "ㄹ" or (next_L is not None and _CHO[next_L] == "ㄹ"):
return "l"
return "n"
# ㄹ medial: r between vowels or before ㅎ; l before other consonants or after ㄴ and ㄹ; n after other consonants citeturn1view0
if L == 5:
if prev_T_is_vowel: # between vowels
return "r"
if next_L is not None and _CHO[next_L] == "ㅎ":
return "r"
if prev_coda_jamo in ("ㄴ", "ㄹ"):
return "l"
# before other consonants
if next_L is not None and _CHO[next_L] != "ㅇ":
return "l"
# after other consonants
return "n"
# ㄱ medial onset: g between vowels or after ㄴㄹㅁㅇ; k after other consonants citeturn1view0
if L == 0:
if prev_T_is_vowel:
return "g"
if prev_coda_jamo in ("ㄴ", "ㄹ", "ㅁ", "ㅇ"):
return "g"
return "k"
# ㄷ medial onset: d between vowels or after ㄴㅁㅇ; t after ㄱㅂㄹㅅ citeturn1view0
if L == 3:
if prev_T_is_vowel:
return "d"
if prev_coda_jamo in ("ㄴ", "ㅁ", "ㅇ"):
return "d"
if prev_coda_jamo in ("ㄱ", "ㅂ", "ㄹ", "ㅅ"):
return "t"
return "d"
# ㅂ medial onset: b between vowels or after ㄴㄹㅁㅇ; m before ㄴㄹㅁ; p otherwise citeturn1view0
if L == 7:
if next_L is not None and _CHO[next_L] in ("ㄴ","ㄹ","ㅁ"):
return "m"
if prev_T_is_vowel:
return "b"
if prev_coda_jamo in ("ㄴ","ㄹ","ㅁ","ㅇ"):
return "b"
return "p"
# ㅅ onset: sh before ㅟ, else s citeturn1view0
if L == 9:
return "sh" if V == _VOWEL_WI else "s"
# ㅈ medial onset: j between vowels or after ㄴㅁㅇ; ch after other consonants citeturn1view0
if L == 12:
if prev_T_is_vowel:
return "j"
if prev_coda_jamo in ("ㄴ","ㅁ","ㅇ"):
return "j"
return "ch"
# ㅊ onset: always ch' as syllabic initial citeturn1view0
if L == 14:
return "ch'"
# ㅋ onset: always k'
if L == 15:
return "k'"
# ㅌ onset: t' generally; t after ㄱㄷㅅㅈ when consonant-following rule applies citeturn1view0
if L == 16:
if prev_coda_jamo in ("ㄱ","ㄷ","ㅅ","ㅈ"):
return "t"
return "t'"
# ㅍ onset: always p' as syllabic initial
if L == 17:
return "p'"
# ㅎ onset: h after ㄱㅂㅅ; ch' after ㄷㅈ; else h citeturn1view0
if L == 18:
if prev_coda_jamo in ("ㄱ","ㅂ","ㅅ"):
return "h"
if prev_coda_jamo in ("ㄷ","ㅈ"):
return "ch'"
return "h"
# Tense consonants: ㄲ/ㄸ/ㅃ/ㅆ/ㅉ fixed
if L == 1: # ㄲ
return "kk"
if L == 4: # ㄸ
return "tt"
if L == 8: # ㅃ
return "pp"
if L == 10: # ㅆ
return "ss"
if L == 13: # ㅉ
return "tch"
# fallback (shouldn't happen)
return ["k","kk","n","t","tt","r","m","p","pp","s","ss","","ch","tch","ch'","k'","t'","p'","h"][L]
def _ala_coda(T: int, next_L: int | None, next_V: int | None, next_is_hangul: bool) -> str:
"""ALA-LC coda (syllabic final) with letter-position rules + double-final consonant rules.
Implements:
- Letter Position Rules (Appendix 7, pp. 64-67). citeturn1view0
- Double consonants / final clusters rules (sections around pp. 10-13). citeturn1view0
Notes:
- Some exceptions (밟-, 넓-) are implemented in a minimal, pattern-based way.
- For perfect reversibility, use variant="reversible".
"""
if T == 0:
return ""
jong = _JONG[T]
# Determine next onset jamo and whether next begins with a vowel (i.e., next onset is ㅇ)
next_cho = _CHO[next_L or _L_IEUNG_INDEX] if next_is_hangul else None
next_is_vowel = bool(next_is_hangul and next_cho == "ㅇ")
# ---- Special rules for ㅎ/ㄶ/ㅀ before vowels (section near p. 9-10). citeturn1view0
if jong == "ㅎ" and next_is_vowel:
return "" # do not romanize
if jong == "ㄶ" and next_is_vowel:
return "n"
if jong == "ㅀ" and next_is_vowel:
return "r"
# ㅀ followed by ㄴ => ll (p. 9). citeturn1view0
if jong == "ㅀ" and next_cho == "ㄴ":
return "ll"
# ---- Double final consonants (clusters) rules (pp. 10-13). citeturn1view0
# (a) Word-final clusters (or before non-hangul): romanize as pronounced
if not next_is_hangul:
# ㄳ, ㄺ -> k; ㄻ -> m; ㄼ, ㄽ -> l; ㅄ -> p (p. 10). citeturn1view0
if jong in ("ㄳ", "ㄺ"):
return "k"
if jong == "ㄻ":
return "m"
if jong in ("ㄼ", "ㄽ"):
return "l"
if jong == "ㅄ":
return "p"
# fallback
return KROMAN_SYSTEMS["ala-lc"]["coda_out"][T] # type: ignore[index]
# (c) Followed by vowels: explicit cluster romanizations (p. 12). citeturn1view0
if next_is_vowel:
if jong == "ㄵ":
return "nj"
if jong == "ㄺ":
return "lg"
if jong == "ㄻ":
return "lm"
if jong == "ㄼ":
return "lb"
if jong == "ㄾ":
return "lt'"
if jong == "ㄿ":
return "lp'"
if jong == "ㅄ":
return "ps"
if jong == "ㅆ":
return "ss"
# ㅎ/ㄶ/ㅀ already handled above
return KROMAN_SYSTEMS["ala-lc"]["coda_out"][T] # type: ignore[index]
# (b) Followed by other consonants: cluster-specific rules (p. 10-11). citeturn1view0
if jong == "ㄲ":
return "k"
if jong == "ㄺ":
if next_cho == "ㄱ":
return "l"
if next_cho == "ㄴ":
return "ng"
return "k"
if jong == "ㄻ":
return "m"
if jong == "ㄵ":
return "n"
if jong in ("ㄼ", "ㄽ", "ㄾ"):
# Exception 1: 밟- => m before ㄴ, else p (p. 11). citeturn1view0
# We can't fully detect stems; this catches the exact syllable 밟.
# Handled outside this function in the caller if needed; here we implement generally:
return "l"
if jong in ("ㅄ", "ㄿ"):
# Exception 1 for 밟- will override in caller when detected.
return "p"
if jong == "ㅆ":
return "n" if next_cho == "ㄴ" else "t"
# Now apply the core ALA-LC *single final* letter-position rules for key finals (Appendix 7). citeturn1view0
if jong == "ㄱ":
return "ng" if next_cho in ("ㄴ", "ㄹ", "ㅁ") else "k"
if jong == "ㄷ":
return "n" if next_cho == "ㄴ" else "t"
if jong == "ㅂ":
return "m" if next_cho in ("ㄴ", "ㄹ", "ㅁ") else "p"
if jong == "ㅈ":
return "n" if next_cho in ("ㄴ", "ㅁ") else "t"
if jong == "ㅊ":
if next_cho == "ㅇ":
return "j"
return "n" if next_cho in ("ㄴ", "ㅁ") else "t"
if jong == "ㅅ":
if next_cho in ("ㄴ", "ㅁ"):
return "n"
if next_cho in ("ㄱ", "ㄷ", "ㅂ", "ㅅ", "ㅈ", "ㅎ"):
return "t"
return "s"
if jong == "ㅎ":
if next_cho == "ㅇ":
return ""
if next_cho == "ㄴ":
return "nn"
return "t"
if jong == "ㄲ":
return "kk" if next_cho == "ㅇ" else "k"
return KROMAN_SYSTEMS["ala-lc"]["coda_out"][T] # type: ignore[index]
next_cho = _CHO[next_L or _L_IEUNG_INDEX]
# ㄱ: NG before ㄴㄹㅁ; otherwise K citeturn1view0
if jong == "ㄱ":
return "ng" if next_cho in ("ㄴ","ㄹ","ㅁ") else "k"
# ㄷ: N before ㄴ, else T citeturn1view0
if jong == "ㄷ":
return "n" if next_cho == "ㄴ" else "t"
# ㅂ: M before ㄴㄹㅁ; else P citeturn1view0
if jong == "ㅂ":
return "m" if next_cho in ("ㄴ","ㄹ","ㅁ") else "p"
# ㅈ: N before ㄴㅁ; else T citeturn1view0
if jong == "ㅈ":
return "n" if next_cho in ("ㄴ","ㅁ") else "t"
# ㅊ: J before vowels (i.e., next onset ㅇ), N before ㄴㅁ, else T citeturn1view0
if jong == "ㅊ":
if next_cho == "ㅇ":
return "j"
return "n" if next_cho in ("ㄴ","ㅁ") else "t"
# ㅅ: N before ㄴㅁ; T before ㄱㄷㅂㅅㅈ; otherwise S before vowels/others. citeturn2view0
if jong == "ㅅ":
if next_cho in ("ㄴ","ㅁ"):
return "n"
if next_cho in ("ㄱ","ㄷ","ㅂ","ㅅ","ㅈ","ㅎ"):
return "t"
# before vowels: s
return "s"
# ㅆ: N before ㄴ; else T citeturn1view0
if jong == "ㅆ":
return "n" if next_cho == "ㄴ" else "t"
# ㅎ: not romanized as syllabic final before vowels; NN before ㄴ; else T citeturn1view0
if jong == "ㅎ":
if next_cho == "ㅇ":
return ""
if next_cho == "ㄴ":
return "nn"
return "t"
# ㄲ: KK before vowels; K otherwise citeturn1view0
if jong == "ㄲ":
return "kk" if next_cho == "ㅇ" else "k"
# For clusters and other finals, fall back to reversible coda_out (MR-like) which is close to ALA-LC examples.
return KROMAN_SYSTEMS["ala-lc"]["coda_out"][T] # type: ignore[index]
def _nk1992_onset(L: int, V: int, word_initial: bool) -> str:
"""DPRK MR-for-DPRK onset, simplified from NGA tables. citeturn3view0"""
if L == _L_IEUNG_INDEX:
return ""
# Initial ㄴ may be not romanized before i/yotized; simplified like ALA-LC. citeturn3view0
if word_initial and L == 2 and (V == _VOWEL_I or V in _VOWELS_YOTIZED):
return ""
# Initial ㄹ may be not romanized before i/yotized; otherwise often n at beginning-of-word in DPRK table.
if word_initial and L == 5:
if V == _VOWEL_I or V in _VOWELS_YOTIZED:
return ""
return "n"
base = ["k","kk","n","t","tt","r","m","p","pp","s","ss","","ch","tch","ch'","k'","t'","p'","h"]
return base[L]
def _nk1992_coda(T: int, next_is_hangul: bool) -> str:
"""DPRK MR-for-DPRK coda, simplified from NGA table 1 (end of word). citeturn3view0"""
if T == 0:
return ""
jong = _JONG[T]
# End-of-word ㅎ is not romanized (table 1)
if jong == "ㅎ" and not next_is_hangul:
return ""
# otherwise MR-like
return KROMAN_SYSTEMS["nk1992"]["coda_out"][T] # type: ignore[index]
# Full Table 3 (word-medial consonant cluster romanizations) and Table 4 (irregular CV forms)
# from the MR-for-DPRK reference. citeturn3view0
#
# We embed the tables in a compact, parseable form. The parser builds a mapping that can be used
# to rewrite the boundary between syllables (previous coda / next onset) to match Table 3, and
# to override certain onset+vowel combinations per Table 4.
_NK_TABLE3_INITIALS = ["ᄀ","ᄂ","ᄃ","ᄅ","ᄆ","ᄇ","ᄉ","ᄋ","ᄌ","ᄎ","ᄏ","ᄐ","ᄑ","ᄒ","ᄁ","ᄄ","ᄈ","ᄊ","ᄍ"]
_NK_TABLE3_ROWS: list[tuple[str, list[str]]] = [
("ᄀ", "kk ngn kt ngn ngm kp ks g kch kch' kk' kt' kp' kh kk ktt kpp kss ktch".split()),
("ᄂ", "n'g nn nd ll nm nb ns n nj nch' nk' nt' np' nh nkk ntt npp nss ntch".split()),
("ᄃ", "kk nn tt nn nm pp ss d tch tch' tk' tt' tp' th tkk tt tpp tss tch".split()),
("ᄅ", "lg ll lt ll lm lb ls r lch lch' lk' lt' lp' rh lkk ltt lpp lss ltch".split()),
("ᄆ", "mg mn md mn mm mb ms m mj mch' mk' mt' mp' mh mkk mtt mpp mss mtch".split()),
("ᄇ", "pk mn pt mn mm pp ps b pch pch' pk' pt' pp' ph pkk ptt pp pss ptch".split()),
("ᄉ", "kk nn tt nn nm pp ss d tch tch' tk' tt' tp' th tkk tt tpp ss tch".split()),
("ᄋ", "ngg ngn ngd ngn ngm ngb ngs ng ngj ngch' ngk' ngt' mgp' ng ngkk ngtt ngpp ngss ngtch".split()),
("vowel", "g n d r m b s j ch' k' t' p' h kk tt pp ss tch".split()),
("ᄌ", "kk nn tt nn nm pp ss d tch tch' tk' tt' tp' th tkk tt tpp ss tch".split()),
("ᄎ", "kk nn tt nn nm pp ss d tch tch' tk' tt' tp' th tkk tt tpp ss tch".split()),
("ᄏ", "kk ngn kt ngn ngm kp ks k kch kcch' kk' kt' kp' kh kk ktt kpp kss ktch".split()),
("ᄐ", "kk nn tt nn nm pp ss d tch tch' tk' tt' tp' tk tkk tt tpp ss tch".split()),
("ᆰ", "lg ngn kt ngl ngm kp ks lg kch kch' lk' kt' kp' lkh lkk kt kpp kss ktch".split()),
("ᆱ", "mg mn md ml lm mb ms lm mj mch' mk' mt' mp' mh mkk mtt mpp mss mtch".split()),
("ᆲ", "pk mn pt ml mm lb ps lb pch pch' pk' pt' lp' lph pkk ptt lpp pss ptch".split()),
("ᆬ", "nk nn nt nl nm nb ns nj nj nch' nk' nt' np' nh nkk ntt npp nss ntch".split()),
("ᆭ", "nk nn nt nl nm nb ns nh nj nch' nk' nt' np' nh nkk ntt npp nss ntch".split()),
("ㅄ", "pk pn pt pl pm pp ps ps pj pch' pk' pt' pp' ph pkk ptt pp pss ptch".split()),
("ㄲ", "kk ngn kt ngn ngm kp ks g kch kch' kk' kt' kp' kh kk ktt kpp kss ktch".split()),
("ㅆ", "kk nn tt nn nm pp ss s tch tch' tk' tt' tp' th tkk tt tpp tss tch".split()),
("ㅍ", "pk mn pt mn mm pp ps p pch pch' pk' pt' pp' ph pkk ptt pp pss ptch".split()),
("ㅎ", "k' n t' r m p' s h ch' ch' k' t' p' h kk tt pp ss tch".split()),
("ㅀ", "lk' ll lt' ll lm lp' ls rh lch' lch' lk' lt' lp' rh lkk ltt lpp lss ltch".split()),
]
_NK_TABLE4_OVERRIDES: dict[tuple[str, int, bool], str] = {
("ᄀ", 20, True): "ki",
("ᄀ", 20, False): "gi",
("ᄂ", 2, True): "ya", ("ᄂ", 6, True): "yŏ", ("ᄂ", 12, True): "yo", ("ᄂ", 17, True): "yu",
("ᄂ", 20, True): "i", ("ᄂ", 7, True): "ye",
("ᄂ", 2, False): "nya", ("ᄂ", 6, False): "nyŏ", ("ᄂ", 12, False): "nyo", ("ᄂ", 17, False): "nyu",
("ᄂ", 20, False): "ni", ("ᄂ", 7, False): "nye",
("ᄃ", 20, True): "ti", ("ᄃ", 20, False): "di",
("ᄌ", 20, True): "chi", ("ᄌ", 20, False): "ji",
("ᄉ", 16, True): "shwi", ("ᄉ", 16, False): "shwi",
}