Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Aug 20, 2024
1 parent 7b2531a commit 79d44c3
Show file tree
Hide file tree
Showing 20 changed files with 30,911 additions and 1,325 deletions.
6 changes: 6 additions & 0 deletions base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def file_size(p: Path):

# 初始化其他自定义数据
pinyin_to: Dict[str, Ldata] = {}
pinyin_to["mps2"] = load_json("py2mps2") # 汉语拼音至注音二式
pinyin_to["typy"] = load_json("py2ty") # 汉语拼音至通用拼音
pinyin_to["yale"] = load_json("py2yale") # 汉语拼音至耶鲁拼音
pinyin_to["ipa"] = load_json("py2ipa") # 汉语拼音至IPA
pinyin_to["wadegiles"] = load_json("py2wg") # 汉语拼音至威妥玛拼音
pinyin_to["romatzyh"] = load_json("py2gr") # 汉语拼音至国语罗马字
Expand All @@ -64,6 +67,9 @@ def file_size(p: Path):

fixed_zh: Dict[str, Ldata] = {}
fixed_zh["zh_py"] = load_json("fixed_zh_py") # 汉语拼音修正
fixed_zh["zh_mps2"] = load_json("fixed_zh_mps2") # 注音二式修正
fixed_zh["zh_ty"] = load_json("fixed_zh_ty") # 通用拼音修正
fixed_zh["zh_yale"] = load_json("fixed_zh_yale") # 耶鲁拼音修正
fixed_zh["zh_wg"] = load_json("fixed_zh_wg") # 威妥玛拼音修正
fixed_zh["zh_gr"] = load_json("fixed_zh_gr") # 国语罗马字修正
fixed_zh["zh_cy"] = load_json("fixed_zh_cy") # 西里尔转写修正
Expand Down
79 changes: 78 additions & 1 deletion converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,81 @@ def to_pinyin(text: str, rep: Ldata, auto_cut: bool = True) -> str:
return capitalize_lines(capitalize_titles(replace_multiple(result, rep)))


def to_mps2(text: str, rep: Ldata, auto_cut: bool = True) -> str:
"""
将字符串中的汉字转写为注音符号第二式,单字之间使用连字符分开,词之间使用空格分开。
Args:
text (str): 需要转换的字符串
rep (Ldata): 需要替换格式的内容
auto_cut (bool, optional): 是否自动分词,默认为True
Returns:
str: 转换结果
"""

seg_list = segment_str(text, auto_cut)
output_list: List[str] = []

for seg in seg_list:
pinyin_list = lazy_pinyin(seg, style=Style.TONE3, neutral_tone_with_five=True)
mps2_list = [pinyin_to["mps2"].get(p, p) for p in pinyin_list]
output_list.append("-".join(mps2_list))

result = " ".join(output_list)
return capitalize_lines(capitalize_titles(replace_multiple(result, rep)))


def to_tongyong(text: str, rep: Ldata, auto_cut: bool = True) -> str:
"""
将字符串中的汉字转写为通用拼音,单字之间使用连字符分开,词之间使用空格分开。
Args:
text (str): 需要转换的字符串
rep (Ldata): 需要替换格式的内容
auto_cut (bool, optional): 是否自动分词,默认为True
Returns:
str: 转换结果
"""

seg_list = segment_str(text, auto_cut)
output_list: List[str] = []

for seg in seg_list:
pinyin_list = lazy_pinyin(seg, style=Style.TONE3, neutral_tone_with_five=True)
typy_list = [pinyin_to["typy"].get(p, p) for p in pinyin_list]
output_list.append("-".join(typy_list))

result = " ".join(output_list)
return capitalize_lines(capitalize_titles(replace_multiple(result, rep)))


def to_yale(text: str, rep: Ldata, auto_cut: bool = True) -> str:
"""
将字符串中的汉字转写为耶鲁拼音,单字之间使用连字符分开,词之间使用空格分开。
Args:
text (str): 需要转换的字符串
rep (Ldata): 需要替换格式的内容
auto_cut (bool, optional): 是否自动分词,默认为True
Returns:
str: 转换结果
"""

seg_list = segment_str(text, auto_cut)
output_list: List[str] = []

for seg in seg_list:
pinyin_list = lazy_pinyin(seg, style=Style.TONE3, neutral_tone_with_five=True)
yale_list = [pinyin_to["yale"].get(p, p) for p in pinyin_list]
output_list.append("-".join(yale_list))

result = " ".join(output_list)
return capitalize_lines(capitalize_titles(replace_multiple(result, rep)))


def to_ipa(text: str) -> str:
"""
将字符串中的汉字转写为IPA,单字之间使用空格分开。
Expand Down Expand Up @@ -270,7 +345,9 @@ def to_bopomofo(text: str) -> str:
str: 转换结果
"""

return " ".join(lazy_pinyin(text, style=Style.BOPOMOFO))
bpmf_list = lazy_pinyin(text, style=Style.BOPOMOFO)
bpmf_list = [f"˙{i[:-1]}" if i.endswith("˙") else i for i in bpmf_list]
return " ".join(bpmf_list)


def to_wadegiles(text: str, rep: Ldata, auto_cut: bool = True) -> str:
Expand Down
6 changes: 3 additions & 3 deletions data/fixed_zh_cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@
"block.minecraft.banner.triangle_top.red": "Дин хун саньцзяо",
"block.minecraft.banner.triangle_top.white": "Дин бай саньцзяо",
"block.minecraft.banner.triangle_top.yellow": "Дин хуан саньцзяо",
"commands.debug.function.noReturnRun": "Шиюн /return жунь ши уфа чжуйцзун",
"debug.copy_location.help": "F3 + C = юн /tp минлин дэ синши фучжи ни дэ вэйчжи, аньчжу F3 + C ши юси бэнкуй",
"commands.debug.function.noReturnRun": "Шиюн \/return жунь ши уфа чжуйцзун",
"debug.copy_location.help": "F3 + C = юн \/tp минлин дэ синши фучжи ни дэ вэйчжи, аньчжу F3 + C ши юси бэнкуй",
"optimizeWorld.stage.failed": "Шибай лэ! :(",
"selectWorld.allowCommands.info": "Лижу /gamemode、/experience дэн минлин"
"selectWorld.allowCommands.info": "Лижу \/gamemode、\/experience дэн минлин"
}
6 changes: 3 additions & 3 deletions data/fixed_zh_gr.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@
"block.minecraft.banner.triangle_top.red": "Diing horng sanjeau",
"block.minecraft.banner.triangle_top.white": "Diing bair sanjeau",
"block.minecraft.banner.triangle_top.yellow": "Diing hwang sanjeau",
"commands.debug.function.noReturnRun": "Shyyyonq /return run shyr wufaa jueitzong",
"debug.copy_location.help": "F3 + C = yonq /tp minqlinq .de shyngshyh fuhjyh nii .de weyjyh, annjuh F3 + C shyy youshih bengkuey",
"commands.debug.function.noReturnRun": "Shyyyonq \/return run shyr wufaa jueitzong",
"debug.copy_location.help": "F3 + C = yonq \/tp minqlinq .de shyngshyh fuhjyh nii .de weyjyh, annjuh F3 + C shyy youshih bengkuey",
"optimizeWorld.stage.failed": "Shybay .lhe! :(",
"selectWorld.allowCommands.info": "Lihru /gamemode、/experience deeng minqlinq"
"selectWorld.allowCommands.info": "Lihru \/gamemode、\/experience deeng minqlinq"
}
Loading

0 comments on commit 79d44c3

Please sign in to comment.