WR / text /meow.py
Naozumi0512's picture
init
e62fb95
raw
history blame contribute delete
No virus
1.08 kB
import re
from functools import reduce
JP_2_WR = {
"a": "ä",
"ää": "a",
"ae": "æ",
"oe": "ö",
"eo": "ö",
"yu": "ü",
"j": "y",
}
def jp2wr(jp):
return re.sub(
"(g|k)u(?!ng|k)",
"\\1wu",
reduce(lambda pron, rule: pron.replace(*rule), JP_2_WR.items(), jp),
)
WR_2_JP = {
"y": "j",
"ü": "yu",
"öi": "eoi",
"ö": "oe",
"æ": "ae",
"a": "aa",
"ä": "a",
}
def wr2jp(wr):
return re.sub(
"(g|k)wu(?!ng|k)",
"\\1u",
reduce(lambda pron, rule: pron.replace(*rule), WR_2_JP.items(), wr),
)
# Works for both jp and wr
def split_syllable(syllable):
# Find the index of the first vowel. If "y" is at the beginning, it’s the initial (for the case of wr), otherwise it’s part of the rhyme (for the case of jp)
index = next((i for i, c in enumerate(syllable) if c in ("aeiouäöüæ" if syllable[0] == "y" else "aeiouyäöüæ")), 0)
return (syllable[:index], syllable[index:-1], syllable[-1])
print([split_syllable(j) for j in ['äm3']])