大须大镜 | Mayahilwa Mayakimhemot/ toolbox/ 目度 Systemedo

【音节分割】正字法切音

tool python

将拉丁正字写法的语句,按照泷文字母所代表的音进行切分。

示例

输入你想要切音的词句

TALUSHAL BUHHIAYUKANOL KUOTO, USUTOT OS LÄPHASA BUHNEMO KUBBAPULEH KUBHAMA ILAH CHIMAYL DHELATA. 

切音后的词句

-ta-lu-sha-l -bu-h-hi-ra-yu-ka-no-l -ku-ro-to, -ru-su-to-t -ro-s -lä-p-ha-sa -bu-h-ne-mo -ku-b-ba-pu-le-h -ku-b-ha-ma -ri-la-h -chi-ma-y-l -dhe-la-ta.

Python解译器代码

# 定义python文件路径
with open(r'------\【音节分割】正字法切音.py', 'r', encoding='utf-8') as file:
    code = file.read()
exec(code)

【音节分割】正字法切音.py

# 设定字母集
vowels = 'aiueoä'
single_letter_consonants = 'rywnmhfpbkgcxtdszlq'
multi_letter_consonants = ['jn', 'ch', 'dh', 'sh', 'cq', 'dq', 'sq']
split_letter_consonants = ['jh', 'jq']

# 处理单词
def process_word(word):
    word = word.lower()  # 将单词小写化
    result = []  # 存储处理后的结果
    i = 0  # 字母在单词内的索引
    while i < len(word):
        # python截断操作包含括号前一个索引,不含后一个
        if i + 1 < len(word) and word[i:i+2] in multi_letter_consonants:
            # 处理多字母辅音
            result.append('-' + word[i:i+2])
            i += 2
        elif i + 1 < len(word) and word[i:i+2] in split_letter_consonants:
            # 处理易混辅音簇
            result.append('-' + word[i+1:i+2])
            i += 2
        elif word[i] in single_letter_consonants:
            # 处理单字母辅音
            result.append('-' + word[i])
            i += 1
        elif word[i] in vowels:
            # 处理元音
            if i == 0:
                # 首字母为元音
                result.append('-r' + word[i])
                i += 1
            elif word[i-1] in vowels:
                # 前一字母为元音
                result.append('-r' + word[i])
                i += 1
            elif not word[i-1] in single_letter_consonants:
                # 前一字符非辅音
                result.append('-r' + word[i])
                i += 1
            else:
                # 前一字母为辅音
                result.append(word[i])
                i += 1
        else:
            # 处理符号和其它字符
            result.append(word[i])
            i += 1
    return ''.join(result)

# 主函数
def main():
    try:
        # 处理切音
        sentence = input("请输入你想要切音的词句:")
        sliced_sentence = process_word(sentence)
        print("切音后的词句:")
        print(sliced_sentence)
    except Exception as e:
        print(f"发生错误:{e}")
        input("按 Enter 键退出...")

if __name__ == "__main__":
    main()