// Korean Base Phonetic Rules
// ==========================
// Phonetic rules for Korean (한국어) using Hangul script.
// Maps Hangul jamo to Latin phonetic representations using
// Revised Romanization of Korean (RR).
//
// Note: Korean syllable blocks are pre-composed characters.
// This file handles individual jamo (letters) which appear
// in decomposed form or as compatibility characters.
//
// Key features:
// - Hangul jamo (consonants and vowels) to Latin
// - Double consonants (ㄲ, ㄸ, ㅃ, ㅆ, ㅉ) → tensed consonants
// - Vowel combinations and diphthongs
// - Initial vs final consonant pronunciation differences
//
// Rule IDs: 2050-2149
@name "Korean Base Phonetic Rules"
@version "1.0.0"
@author "liblevenshtein"
@description "Phonetic normalization rules for Korean Hangul"
// ============================================================
// TENSE (DOUBLE) CONSONANTS ([:tense:] class) - Higher priority
// ============================================================
// Korean tense consonants (ssang) with IPA tenseness marker ͈ (U+0348)
// These need to match before single consonants
// ㄲ (ssang-giyeok) → k͈ (tense velar stop)
[id: 2050, name: "ssang giyeok tense", weight: 0.05, group: korean_tense_consonants, ipa: "/k͈/"]
ㄲ -> k͈;
// ㄸ (ssang-digeut) → t͈ (tense alveolar stop)
[id: 2051, name: "ssang digeut tense", weight: 0.05, group: korean_tense_consonants, ipa: "/t͈/"]
ㄸ -> t͈;
// ㅃ (ssang-bieup) → p͈ (tense bilabial stop)
[id: 2052, name: "ssang bieup tense", weight: 0.05, group: korean_tense_consonants, ipa: "/p͈/"]
ㅃ -> p͈;
// ㅆ (ssang-siot) → s͈ (tense alveolar fricative)
[id: 2053, name: "ssang siot tense", weight: 0.05, group: korean_tense_consonants, ipa: "/s͈/"]
ㅆ -> s͈;
// ㅉ (ssang-jieut) → t͡ɕ͈ (tense alveolo-palatal affricate)
[id: 2054, name: "ssang jieut tense", weight: 0.05, group: korean_tense_consonants, ipa: "/t͡ɕ͈/"]
ㅉ -> t͡ɕ͈;
// ============================================================
// ASPIRATED CONSONANTS ([:aspirated:] class)
// ============================================================
// These use IPA aspiration marker ʰ (U+02B0)
// ㅋ (kieuk) → kʰ (aspirated velar stop)
[id: 2060, name: "kieuk aspirated", weight: 0.1, group: korean_aspirated, ipa: "/kʰ/"]
ㅋ -> kʰ;
// ㅌ (tieut) → tʰ (aspirated alveolar stop)
[id: 2061, name: "tieut aspirated", weight: 0.1, group: korean_aspirated, ipa: "/tʰ/"]
ㅌ -> tʰ;
// ㅍ (pieup) → pʰ (aspirated bilabial stop)
[id: 2062, name: "pieup aspirated", weight: 0.1, group: korean_aspirated, ipa: "/pʰ/"]
ㅍ -> pʰ;
// ㅊ (chieut) → t͡ɕʰ (aspirated alveolo-palatal affricate)
[id: 2063, name: "chieut aspirated", weight: 0.1, group: korean_aspirated, ipa: "/t͡ɕʰ/"]
ㅊ -> t͡ɕʰ;
// ============================================================
// BASIC CONSONANTS
// ============================================================
// ㄱ (giyeok) → ɡ/k (varies by position)
[id: 2070, name: "giyeok", weight: 0.15, group: korean_consonants, ipa: "/ɡ/"]
ㄱ -> ɡ;
// ㄴ (nieun) → n
[id: 2071, name: "nieun", weight: 0.15, group: korean_consonants]
ㄴ -> n;
// ㄷ (digeut) → d/t (varies by position)
[id: 2072, name: "digeut", weight: 0.15, group: korean_consonants]
ㄷ -> d;
// ㄹ (rieul) → r/l (varies by position)
[id: 2073, name: "rieul", weight: 0.15, group: korean_consonants]
ㄹ -> r;
// ㅁ (mieum) → m
[id: 2074, name: "mieum", weight: 0.15, group: korean_consonants]
ㅁ -> m;
// ㅂ (bieup) → b/p (varies by position)
[id: 2075, name: "bieup", weight: 0.15, group: korean_consonants]
ㅂ -> b;
// ㅅ (siot) → s
[id: 2076, name: "siot", weight: 0.15, group: korean_consonants]
ㅅ -> s;
// ㅇ (ieung) → silent initially, ŋ finally
// When initial, it's a placeholder (silent)
// When final, it represents velar nasal
[id: 2077, name: "ieung", weight: 0.15, group: korean_consonants, ipa: "/ŋ/"]
ㅇ -> ŋ;
// ㅈ (jieut) → t͡ɕ (alveolo-palatal affricate)
[id: 2078, name: "jieut", weight: 0.15, group: korean_consonants, ipa: "/t͡ɕ/"]
ㅈ -> t͡ɕ;
// ㅎ (hieut) → h
[id: 2079, name: "hieut", weight: 0.15, group: korean_consonants]
ㅎ -> h;
// ============================================================
// COMPOUND FINAL CONSONANTS
// ============================================================
// ㄳ (giyeok-siot) → ks
[id: 2080, name: "giyeok siot", weight: 0.1, group: korean_compound_finals]
ㄳ -> ks;
// ㄵ (nieun-jieut) → nj
[id: 2081, name: "nieun jieut", weight: 0.1, group: korean_compound_finals]
ㄵ -> nj;
// ㄶ (nieun-hieut) → nh
[id: 2082, name: "nieun hieut", weight: 0.1, group: korean_compound_finals]
ㄶ -> nh;
// ㄺ (rieul-giyeok) → lg
[id: 2083, name: "rieul giyeok", weight: 0.1, group: korean_compound_finals]
ㄺ -> lg;
// ㄻ (rieul-mieum) → lm
[id: 2084, name: "rieul mieum", weight: 0.1, group: korean_compound_finals]
ㄻ -> lm;
// ㄼ (rieul-bieup) → lb
[id: 2085, name: "rieul bieup", weight: 0.1, group: korean_compound_finals]
ㄼ -> lb;
// ㄽ (rieul-siot) → ls
[id: 2086, name: "rieul siot", weight: 0.1, group: korean_compound_finals]
ㄽ -> ls;
// ㄾ (rieul-tieut) → lt
[id: 2087, name: "rieul tieut", weight: 0.1, group: korean_compound_finals]
ㄾ -> lt;
// ㄿ (rieul-pieup) → lp
[id: 2088, name: "rieul pieup", weight: 0.1, group: korean_compound_finals]
ㄿ -> lp;
// ㅀ (rieul-hieut) → lh
[id: 2089, name: "rieul hieut", weight: 0.1, group: korean_compound_finals]
ㅀ -> lh;
// ㅄ (bieup-siot) → ps
[id: 2090, name: "bieup siot", weight: 0.1, group: korean_compound_finals]
ㅄ -> ps;
// ============================================================
// BASIC VOWELS
// ============================================================
// ㅏ (a) → a
[id: 2100, name: "vowel a", weight: 0.2, group: korean_vowels]
ㅏ -> a;
// ㅓ (eo) → eo
[id: 2101, name: "vowel eo", weight: 0.2, group: korean_vowels]
ㅓ -> eo;
// ㅗ (o) → o
[id: 2102, name: "vowel o", weight: 0.2, group: korean_vowels]
ㅗ -> o;
// ㅜ (u) → u
[id: 2103, name: "vowel u", weight: 0.2, group: korean_vowels]
ㅜ -> u;
// ㅡ (eu) → eu
[id: 2104, name: "vowel eu", weight: 0.2, group: korean_vowels]
ㅡ -> eu;
// ㅣ (i) → i
[id: 2105, name: "vowel i", weight: 0.2, group: korean_vowels]
ㅣ -> i;
// ㅐ (ae) → ae
[id: 2106, name: "vowel ae", weight: 0.2, group: korean_vowels]
ㅐ -> ae;
// ㅔ (e) → e
[id: 2107, name: "vowel e", weight: 0.2, group: korean_vowels]
ㅔ -> e;
// ============================================================
// Y-COMBINATION VOWELS (Iotized vowels)
// ============================================================
// ㅑ (ya) → ya
[id: 2110, name: "vowel ya", weight: 0.2, group: korean_y_vowels]
ㅑ -> ya;
// ㅕ (yeo) → yeo
[id: 2111, name: "vowel yeo", weight: 0.2, group: korean_y_vowels]
ㅕ -> yeo;
// ㅛ (yo) → yo
[id: 2112, name: "vowel yo", weight: 0.2, group: korean_y_vowels]
ㅛ -> yo;
// ㅠ (yu) → yu
[id: 2113, name: "vowel yu", weight: 0.2, group: korean_y_vowels]
ㅠ -> yu;
// ㅒ (yae) → yae
[id: 2114, name: "vowel yae", weight: 0.2, group: korean_y_vowels]
ㅒ -> yae;
// ㅖ (ye) → ye
[id: 2115, name: "vowel ye", weight: 0.2, group: korean_y_vowels]
ㅖ -> ye;
// ============================================================
// W-COMBINATION VOWELS (Labial glide vowels)
// ============================================================
// ㅘ (wa) → wa
[id: 2120, name: "vowel wa", weight: 0.2, group: korean_w_vowels]
ㅘ -> wa;
// ㅙ (wae) → wae
[id: 2121, name: "vowel wae", weight: 0.2, group: korean_w_vowels]
ㅙ -> wae;
// ㅚ (oe) → oe (or we in modern pronunciation)
[id: 2122, name: "vowel oe", weight: 0.2, group: korean_w_vowels]
ㅚ -> oe;
// ㅝ (wo) → wo
[id: 2123, name: "vowel wo", weight: 0.2, group: korean_w_vowels]
ㅝ -> wo;
// ㅞ (we) → we
[id: 2124, name: "vowel we", weight: 0.2, group: korean_w_vowels]
ㅞ -> we;
// ㅟ (wi) → wi
[id: 2125, name: "vowel wi", weight: 0.2, group: korean_w_vowels]
ㅟ -> wi;
// ㅢ (ui) → ui (or i after consonants)
[id: 2126, name: "vowel ui", weight: 0.2, group: korean_w_vowels]
ㅢ -> ui;
// ============================================================
// COMMON SYLLABLE SIMPLIFICATIONS
// ============================================================
// Simplify double romanizations for easier matching
[id: 2140, name: "eo to o", weight: 0.3, group: korean_simplification]
eo -> o;
[id: 2141, name: "eu to u", weight: 0.3, group: korean_simplification]
eu -> u;
[id: 2142, name: "ae to e", weight: 0.3, group: korean_simplification]
ae -> e;
// ============================================================
// POSITION-DEPENDENT CONSONANT RULES
// ============================================================
// Korean consonants change pronunciation based on position:
// - Initial: before vowel (word-initial or syllable-initial)
// - Final: at end of syllable (batchim / 받침)
// - Intervocalic: between vowels (typically voiced)
//
// These rules run AFTER basic jamo conversion to adjust
// the IPA output based on phonetic environment.
// Define vowel set for context matching
@define KOREAN_VOWEL = [aeiou]
// ------------------------------
// ㅇ (ieung) position rules
// ------------------------------
// Initial ㅇ is silent (placeholder for vowel-initial syllables)
// Final ㅇ is /ŋ/ (already covered in basic rules)
// ieung is silent at word start (before vowel)
[id: 2150, name: "ieung initial silent", weight: 0.01, group: korean_position]
ŋ -> / # _ $KOREAN_VOWEL;
// ieung is silent between vowels (as initial of second syllable)
[id: 2151, name: "ieung intervocalic silent", weight: 0.01, group: korean_position]
ŋ -> / $KOREAN_VOWEL _ $KOREAN_VOWEL;
// ------------------------------
// ㄹ (rieul) position rules
// ------------------------------
// Initial: /r/ (flap, similar to Spanish r)
// Final: /l/ (lateral)
// Between vowels: /r/ (flap)
// rieul becomes /l/ at word end
[id: 2152, name: "rieul final l", weight: 0.01, group: korean_position]
r -> l / _ #;
// rieul becomes /l/ before consonant
[id: 2153, name: "rieul preconsonantal l", weight: 0.01, group: korean_position]
r -> l / _ [ktnmpsh];
// ------------------------------
// Coda neutralization (final position)
// ------------------------------
// In final position (batchim), many consonants neutralize:
// ㄱ, ㅋ, ㄲ → /k̚/ (unreleased k)
// ㄷ, ㅌ, ㅅ, ㅆ, ㅈ, ㅊ, ㅎ → /t̚/ (unreleased t)
// ㅂ, ㅍ → /p̚/ (unreleased p)
// ɡ/k becomes unreleased k at word end
[id: 2154, name: "velar final unreleased", weight: 0.02, group: korean_position]
ɡ -> k / _ #;
// Aspirated k also unreleases at word end
[id: 2155, name: "aspirated k final", weight: 0.02, group: korean_position]
kk -> k / _ #;
// d/t becomes unreleased t at word end
[id: 2156, name: "dental final unreleased", weight: 0.02, group: korean_position]
d -> t / _ #;
// s becomes t at word end (coda neutralization)
[id: 2157, name: "siot final t", weight: 0.02, group: korean_position]
s -> t / _ #;
// ss (double siot) also becomes t finally
[id: 2158, name: "ssang siot final t", weight: 0.02, group: korean_position]
ss -> t / _ #;
// h becomes silent or very weak at word end
[id: 2159, name: "hieut final weak", weight: 0.02, group: korean_position]
h -> / _ #;
// b/p becomes unreleased p at word end
[id: 2160, name: "bilabial final unreleased", weight: 0.02, group: korean_position]
b -> p / _ #;
// pp becomes p finally
[id: 2161, name: "ssang bieup final p", weight: 0.02, group: korean_position]
pp -> p / _ #;
// ------------------------------
// Intervocalic voicing
// ------------------------------
// Plain consonants between vowels often become voiced
// k between vowels stays as ɡ (already ɡ from basic rules)
// This is already handled since ㄱ → ɡ
// t between vowels can voice to d
[id: 2162, name: "t intervocalic voicing", weight: 0.02, group: korean_position]
t -> d / $KOREAN_VOWEL _ $KOREAN_VOWEL;
// p between vowels can voice to b
[id: 2163, name: "p intervocalic voicing", weight: 0.02, group: korean_position]
p -> b / $KOREAN_VOWEL _ $KOREAN_VOWEL;
// ------------------------------
// Palatalization before /i/, /y/
// ------------------------------
// s + i/y → ɕ (palatalized s)
// s before i becomes palatal
[id: 2164, name: "siot palatalization i", weight: 0.01, group: korean_position]
si -> ɕi;
// ss before i becomes tense palatal
[id: 2165, name: "ssang siot palatalization i", weight: 0.01, group: korean_position]
ssi -> ɕɕi;
// t + i → t͡ɕi (affrication before i)
[id: 2166, name: "digeut affrication i", weight: 0.01, group: korean_position]
ti -> t͡ɕi;
// d + i → d͡ʑi (voiced affrication before i)
[id: 2167, name: "digeut voiced affrication i", weight: 0.01, group: korean_position]
di -> d͡ʑi;
// ------------------------------
// Nasalization
// ------------------------------
// Stops become nasals before nasals
// k/ɡ before n/m becomes ŋ
[id: 2168, name: "velar nasalization", weight: 0.02, group: korean_position]
ɡ -> ŋ / _ [nm];
// t/d before n/m becomes n
[id: 2169, name: "dental nasalization", weight: 0.02, group: korean_position]
d -> n / _ [nm];
// p/b before n/m becomes m
[id: 2170, name: "bilabial nasalization", weight: 0.02, group: korean_position]
b -> m / _ [nm];