Skip to content

Commit

Permalink
fix: chewing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorSuperTux committed Aug 6, 2024
1 parent 7353bc1 commit 3a63944
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions commands/tocfl/chewing.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,12 @@
"yuan": "ㄩㄢ",
"yun": "ㄩㄣ",
"yong": "ㄩㄥ",
# v is used to replace ü in typing
"nü": "ㄋㄩ",
"lü": "ㄌㄩ",
"nv": "ㄋㄩ",
"lv": "ㄌㄩ",
}

PINYIN_CENTER = {
"i": "ㄧ",
"u": "ㄨ",
"u": "ㄨ", # also ㄩ
"ü": "ㄩ",
"v": "ㄩ",
}

# The designer of Hanyu Pinyin used e to represent both 「ㄜ」 and 「ㄝ」.
Expand Down Expand Up @@ -170,24 +164,33 @@ def match_chewing(string: str, index: int, target: dict[str, str]):
# Resolve duplicates
if target == PINYIN_COMBINED:
if target_str == "uan" and string[index - 1] in [
"y",
"j",
"q",
"x",
]:
result = "ㄩㄢ"
elif target_str == "un" and string[index - 1] in [
"y",
"j",
"q",
"x",
]:
result = "ㄩㄣ"
elif target == PINYIN_CENTER:
if target_str == "u" and string[index - 1] in ["j", "q", "x"]:
result = "ㄩ"
elif target == PINYIN_FINALS:
if target_str == "e" and string[index - 1] == "y":
if target_str == "e" and string[index - 1] in "iü":
result = "ㄝ"
# TODO separate those which can have j, q, x as the initial constant
# FIXME ugly bad code
elif target_str == "en" and (string[index - 1] in ["j", "q", "x"] or string[index - 2] in ["j", "q", "x"]):
continue

return (index + i, result)
if target == PINYIN_COMBINED:
if forms_new_word(string, index + i):
return (index + i, result)
else:
return (index + i, result)
return (index + 1, None)


Expand All @@ -203,7 +206,16 @@ def forms_new_word(pinyin: str, index: int):

def to_chewing(pinyin: str) -> str:
# Remove leading and trailing spaces
<<<<<<< Updated upstream
pinyin = pinyin.strip().lower()
=======
pinyin = pinyin.strip()
# Handle all capital letters and lower-case letters
pinyin = pinyin.lower()
<<<<<<< Updated upstream
>>>>>>> Stashed changes
=======
>>>>>>> Stashed changes

# Temporarily store the chewing tones and original index
tones = []
Expand Down

0 comments on commit 3a63944

Please sign in to comment.