OpenCC icon indicating copy to clipboard operation
OpenCC copied to clipboard

fix: 更正 `实时` → `即時` 轉換

Open clover-yan opened this issue 5 months ago • 1 comments

問題描述

在任何情況下,無論地區詞轉換選擇如何,都有 实时即時

:fcitx5-android 在繁體狀態下無法打出 實時

分析

STPhrases.txt 中有 实时即時 的轉換。

https://github.com/BYVoid/OpenCC/blob/46ebc38fe8dd91512843c69bbd4907b11ef84839/data/dictionary/STPhrases.txt#L18635

這個錯誤的轉換在 #826 被引入。但 STPhrases.txt 不應該包括地區詞轉換,否則會導致異常。

解決方案

從 STPhrases.txt 移除該轉換。

參考了 Wikipedia 的公共轉換組,只在 IT 轉換組中找到了規則 Item('real-time', '实时=>zh-tw:即时; 实时=>zh-hk:即时; 实时=>zh-mo:即时;');考慮到該詞的轉換並非在任何情況下都適用,故僅在 TWPhrasesIT.txt 中對應添加轉換。

後續

寫了一個 Python 腳本,基於 pypinyin 庫檢查 STPhrases.txt 中是否有其他錯誤的情況。

pinyincheck.py
import pypinyin
import re

def check_pinyin_similarity_with_tones(file_path):
    """
    讀取文件,判斷每行中文詞組的帶聲調拼音(聲調號碼在後)是否相同,
    並輸出不同的行和行號。

    Args:
        file_path (str): 文件路徑。
    """
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            for line_num, line in enumerate(f, 1):
                parts = re.split(r'[ \t]+', line.strip())

                if len(parts) >= 2:
                    for i in range(len(parts) - 1):
                        phrase1 = parts[0]
                        phrase2 = parts[i + 1]

                        res = tuple(zip([s for s in pypinyin.pinyin(phrase1, style=pypinyin.Style.TONE3, heteronym=True)], [s for s in pypinyin.pinyin(phrase2, style=pypinyin.Style.TONE3, heteronym=True)]))

                        for pinyin1, pinyin2 in res:
                            if not set(pinyin1) & set(pinyin2):
                                print(f"行號: {line_num}, 內容: {line.strip()}, 拼音1: {pinyin1}, 拼音2: {pinyin2}")
                elif len(parts) > 0 and line.strip() != "":
                    print(f"警告: 行號 {line_num} 的格式不正確,跳過: {line.strip()}")

    except FileNotFoundError:
        print(f"錯誤: 文件 '{file_path}' 不存在。請檢查文件路徑。")
    except Exception as e:
        print(f"處理文件時發生錯誤: {e}")

if __name__ == "__main__":
    file_path = input("請輸入文件路徑: ")
    check_pinyin_similarity_with_tones(file_path)

目測結果均爲假陽性。~~運氣就是這麼好。~~

clover-yan avatar Jul 13 '25 02:07 clover-yan

刪除這條轉換規則「实时→實時」應該也行吧? 因爲這倆個字按字轉換都有唯一結果。

lotem avatar Jul 15 '25 13:07 lotem