Skip to content

Instantly share code, notes, and snippets.

@trhura
Last active April 19, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save trhura/264edae302478e51e4ac to your computer and use it in GitHub Desktop.
Save trhura/264edae302478e51e4ac to your computer and use it in GitHub Desktop.
Write Syllable -> IPA mappings for Myanmar Syllables
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
def get_ipa (syllable):
ipa = ''
consonant = syllable[0]
i = 1
while i < len(syllable) and syllable[i] in ['\u103B', '\u103C','\u103D','\u103E']:
i += 1
medial = syllable[1:i]
vowels = syllable[i:]
consonant = get_cons_ipa(consonant)
medial = get_medial_ipa(medial)
vowels = get_vowel_ipa (vowels)
ipa = consonant + medial + vowels
ipa = normalize_ipa (ipa)
return ipa
def normalize_ipa (ipa):
if u"\u028A" in ipa:
ipa = ipa.replace('w', '')
#ipa = ipa.replace('jw'
#ipa = ipa.replace('w', '')
# remove `w` if there is upsilons
# if "ြ" in syllable or "ျ" in syllable:
# ipa = ipa.replace('w', 'j')
# else:
# ipa = ipa.replace('w', '')
ipa = ipa.replace('kj', 'tɕ')
ipa = ipa.replace('kʰj','tɕʰ')
ipa = ipa.replace('ɡj', 'dʑ')
ipa = ipa.replace('jw', 'w')
#ipa = ipa.replace('#', 'ə')
ipa = ipa.replace('j̥', 'ʃ')
ipa = ipa.replace('ŋ̥', 'ŋ̊')
ipa = ipa.replace('ŋj', 'ɲ')
return ipa
def get_cons_ipa (consonant):
cons_symbols = {
'က' : 'k',
'ခ' : 'kʰ',
'ဂ' : 'ɡ',
'ဃ' : 'ɡ',
'င' : 'ŋ',
'စ' : 's',
'ဆ' : 'sʰ',
'ဇ' : 'z',
'ဈ' : 'z',
'ဉ' : 'ɲ',
'ည' : 'ɲ',
'ဋ' : 't',
'ဌ' : 'tʰ',
'ဍ' : 'd',
'ဎ' : 'd',
'ဏ' : 'n',
'တ' : 't',
'ထ' : 'tʰ',
'ဒ' : 'd',
'ဓ' : 'd',
'န' : 'n',
'ပ' : 'p',
'ဖ' : 'pʰ',
'ဗ' : 'b',
'ဘ' : 'b',
'မ' : 'm',
'ယ' : 'j',
'ရ' : 'j',
'လ' : 'l',
'ဝ' : 'w',
'သ' : 'θ',
'ဟ' : 'h',
'ဠ' : 'l',
'အ' : 'ʔ'
}
return cons_symbols.get(consonant, consonant)
def get_medial_ipa(medial):
ipa = ""
if "ှ" in medial:
ipa += u"\u0325"
if "ြ" in medial or "ျ" in medial:
ipa += "j"
if "ွ" in medial:
ipa += "w"
return ipa
def get_vowel_ipa (vowels):
vowels_symbols = {
'' : 'ə',
'ာ' : 'à',
'ာ့' : 'a̰',
'ါ' : 'à',
'ါ့' : 'a̰',
'ား' : 'á',
'ါး' : 'à',
'်' : 'ɛʔ',
'င်' : 'ɪ̀ɴ',
'င့်' : 'ɪ̰ɴ',
'င်း' : 'ɪ́ɴ',
'စ်' : 'ɪʔ',
'ည်' : 'ì',
'ဉ်' : 'ɪ̀ɴ',
'ည့်' : 'ḭ',
'ဉ့်' : 'ɪ̰ɴ',
'ည်း' : 'í',
'ဉ်း' : 'ɪ́ɴ',
'တ်' : 'aʔ',
'န်' : 'àɴ',
'န့်' : 'a̰ɴ',
'န်း' : 'áɴ',
'ပ်' : 'aʔ',
'မ်' : 'àɴ',
'မ့်' : 'a̰ɴ',
'မ်း' : 'áɴ',
'ယ်' : 'ɛ̀',
'ယ်' : 'ɛ̰',
'ံ' : 'àɴ',
'ံ့' : 'a̰ɴ',
'ံး' : 'áɴ',
'ိ' : 'ḭ',
'ိတ်' : 'eɪʔ',
'ိန်' : 'èɪɴ',
'ိန့်' : 'ḛɪɴ',
'ိန်း' : 'éɪɴ',
'ိပ်' : 'eɪʔ',
'ိမ်' : 'èɪɴ',
'ိမ့်' : 'ḛɪɴ',
'ိမ်း' : 'éɪɴ',
'ိံ' : 'èɪɴ',
'ိံ့' : 'ḛɪɴ',
'ိံး' : 'éɪɴ',
'ီ' : 'ì',
'ီး' : 'í',
'ု' : 'ṵ',
'ုတ်' : 'oʊʔ',
'ုန်' : 'òʊɴ',
'ုန့်' : 'o̰ʊɴ',
'ုန်း' : 'óʊɴ',
'ုပ်' : 'oʊʔ',
'ုမ်' : 'òʊɴ',
'ုမ့်' : 'o̰ʊɴ',
'ုမ်း' : 'óʊɴ',
'ုံ' : 'òʊɴ',
'ုံ့' : 'o̰ʊɴ',
'ုံး' : 'óʊɴ',
'ူ' : 'ù',
'ူး' : 'ú',
'ေ' : 'è',
'ေ့' : 'ḛ',
'ေး' : 'é',
'ဲ' : 'ɛ́',
'ဲ့' : 'ɛ̰',
'ော' : 'ɔ́',
'ေါ' : 'ɔ́',
'ော်' : 'aʊʔ',
'ောင်' : 'àʊɴ',
'ောင့်' : 'a̰ʊɴ',
'ောင်း' : 'áʊɴ',
'ော့' : 'ɔ̰',
'ော်' : 'ɔ̀',
'ေါ်' : 'aʊʔ',
'ေါင်' : 'àʊɴ',
'ေါင့်' : 'a̰ʊɴ',
'ေါင်း' : 'áʊɴ',
'ေါ့' : 'ɔ̰',
'ေါ်' : 'ɔ̀',
'ို' : 'ò',
'ို်' : 'aɪʔ',
'ိုင်' : 'àɪɴ',
'ိုင့်' : 'a̰ɪɴ',
'ိုင်း' : 'áɪɴ',
'ို့' : 'o̰',
'ိုး' : 'ó',
'ောက်': 'aʊʔ',
'ေါက်': 'aʊʔ',
#FIXME
'ွတ်' : 'ʊʔ',
'ွန်' : 'ʊ̀ɴ',
'ွမ်း' : 'ʊ́ɴ',
'ွန့်' : 'ʊ̰ɴ',
'ုဏ်' : 'òʊɴ',
'ွန်း' : 'ʊ́ɴ',
'ွပ်' : 'ʊʔ',
'ွမ်' : 'ʊ̀ɴ',
'ွမ့်' : 'ʊ̰ɴ',
'ိုက်' : 'aɪk',
'က်': 'æk',
'သ်' : 'æθ',
'ာတ်' : 'æt',
'ာဒ်' : 'æd',
'ုက်': 'əʊk',
'ုဒ်': 'əʊd',
'ာဘ်' : 'æb',
}
return vowels_symbols.get(vowels, '___UNKNOWN___')
def main():
with open ('ipa-syllables', 'r') as iFile:
for line in iFile:
syllable = line.strip()
print(syllable, '\t', get_ipa(syllable))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment