WR / text /workspace /convert_waitau_jyutping.py
Naozumi0512's picture
init
e62fb95
raw
history blame contribute delete
No virus
393 Bytes
import re
from functools import reduce
ROM_MAPPING = {
"y": "j",
"ü": "yu",
"öi": "eoi",
"ö": "oe",
"a": "aa",
"ä": "a",
"æ": "ae",
}
def rom_map(jyutping):
return re.sub(
"(g|k)u(?!ng|k)",
"\\1wu",
reduce(lambda pron, rule: pron.replace(*rule), ROM_MAPPING.items(), jyutping),
)
converted = rom_map("")
print(converted)