Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Jan 27, 2025
1 parent cbc211f commit 090e4eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ def file_size(p: Path) -> str:

gr_values: Set[str] = set(PINYIN_TO["romatzyh"].values()) # 国语罗马字的有效拼写
cy_values: Set[str] = set(PINYIN_TO["cyrillic"].values()) # 西里尔转写的有效拼写
tone_to_ipa: Ldata = {"1": "˥", "2": "˧˥", "3": "˨˩˦", "4": "˥˩", "5": ""} # IPA声调
TONE_TO_IPA: Final[Ldata] = {
"1": "˥",
"2": "˧˥",
"3": "˨˩˦",
"4": "˥˩",
"5": "",
} # IPA声调

rep_zh: Ldata = load_json("rep_zh") # 连写的中文转写方案替换修正
finals: Tuple[str, ...] = tuple("aāááàoōóǒòeēéěè") # 可能的零声母开头
PINYIN_FINALS: Final[Tuple[str, ...]] = tuple("aāááàoōóǒòeēéěè") # 可能的零声母开头

rep_ja_kk: Ldata = load_json("rep_ja_kk") # 片假名替换修正
8 changes: 4 additions & 4 deletions converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
PINYIN_TO,
gr_values,
cy_values,
tone_to_ipa,
finals,
TONE_TO_IPA,
PINYIN_FINALS,
rep_zh,
rep_ja_kk,
)
Expand Down Expand Up @@ -348,7 +348,7 @@ def to_pinyin(self, text: str) -> str:
(
f"'{py}"
if i > 0
and py.startswith(finals)
and py.startswith(PINYIN_FINALS)
and pinyin_list[i - 1][-1].isalpha()
else py
)
Expand Down Expand Up @@ -414,7 +414,7 @@ def to_ipa(self, text: str) -> str:
"""
pinyin_list = lazy_pinyin(text, style=Style.TONE3, neutral_tone_with_five=True)
ipa_list = [
f"{PINYIN_TO['ipa'].get(p[:-1], p[:-1])}{tone_to_ipa.get(p[-1], p[-1])}"
f"{PINYIN_TO['ipa'].get(p[:-1], p[:-1])}{TONE_TO_IPA.get(p[-1], p[-1])}"
for p in pinyin_list
]
return " ".join(ipa_list)
Expand Down

0 comments on commit 090e4eb

Please sign in to comment.