V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
Elethom

也寫了一個給通訊錄添加注音的工具,支援中日韓語言選擇,支援多音字選擇,提供兩種格式設定

  •  2
     
  •   Elethom ·
    Elethom · Feb 2, 2016 · 3420 views
    This topic created in 3750 days ago, the information mentioned may be changed or developed.

    在 GitHub 上查看

    嘛。懶得寫介紹,直接把 readme 拖過來了。目前 Homebrew 還沒 merge ,請自行編譯安裝。在 Mac 上運行完了就可以直接通過 iCloud 同步到所有設備上去了。

    E 一個畫圖喵一年多沒寫代碼了,就這些,將就著用吧。

    很慚愧,做了一點微小的貢獻,謝謝大家。


    功能:

    • 簡體中文(多音字)
    • 繁體中文(多音字)
    • 日本語
    • 韓語
    • 注音符號
    • 過濾空格

    建議運行的時候加上 -i 參數把所有的注音都重新設定,如果聯繫人只有中國人的話,可以加上 -j-k 忽略掉日本語和韓語。

    關於實現方式:

    • 語言初次判斷用的 Core Foundation 的 tokenizer ,名字比較難判斷語言,所以後面還加了二次對比;
    • 簡繁體中文和韓語用的都是很簡單的 CFStringTransform ,可以參考 NSHipster 的文章
    • 日語因為和中文有很多重合部分,用 CFStringTransform 無法處理, CFStringTransform 本身也沒提供 Kanji -> Romaji 的轉換選項,所以還是直接用了 Core Foundation 的 tokenizer 提取了 Latin transcription ;
    • 過濾 accents and diacritcs 用的也是 CFStringTransform ;
    • 去空格直接手拼 NSString ;
    • API 用了 ABAddressBook ,如果誰有興趣也可以拿 Contacts 重新實現一遍。

    ContactsUtil-PhoneticName

    General

    Add phonetic names to contacts. Supports all CJK characters and multiple formats.

    Install

    With Homebrew:

    $ brew install contacts-phonetic
    

    Compile on your own:

    $ git clone https://github.com/Elethom/ContactsUtil-PhoneticName.git
    $ cd ContactsUtil-PhoneticName
    $ make install
    

    Usage

    -i, --ignore-existing
        Ignore existing phonetic names. Use of this option will update all person entries in the address book.
    
    -m, --keep-marks
        Keep accents and diacritcs.
    
    -s, --keep-spaces
        Keep spaces between characters.
    
    -c, --ignore-chinese
        Ignore Chinese. (Will use Japanese Romaji if both are possible.)
    
    -j, --ignore-japanese
        Ignore Japanese. (Will use Chinese Pinyin if both are possible.)
    
    -k, --ignore-korean
        Ignore Korean.
    

    Example:

    $ contacts-phonetic
    --------------------
    Alice Alstromeria
    --------------------
    Dieter Rams
    --------------------
    Elethom Alstromeria
    --------------------
    ことり 椎名
    椎名 1. Japanese (shiina); 2. Chinese (chuí míng). Select: Select: 1
    Kotori Shiina
    --------------------
    直人 深澤
    直人 1. Japanese (naoto); 2. Chinese (zhí rén). Select: Select: 1
    深澤 1. Japanese (fukazawa); 2. Chinese (shēn zé). Select: Select: 1
    Naoto Fukazawa
    --------------------
    研哉 原
    研哉 1. Japanese (ken'ya); 2. Chinese (yán zāi). Select: Select: 1
    原 1. Japanese (hara); 2. Chinese (yuán). Select: Select: 1
    Ken'ya Hara
    --------------------
    

    License

    This code is distributed under the terms and conditions of the MIT license.

    Donate

    You can support me by:

    :-)

    Contact

    26 replies    2016-02-06 22:59:08 +08:00
    wbsdty331
        1
    wbsdty331  
       Feb 2, 2016
    强行膜
    Elethom
        3
    Elethom  
    OP
       Feb 2, 2016
    @jjgod
    Fixed.
    49
        4
    49  
       Feb 2, 2016 via iPhone
    一个人的命运啊,当然要靠自我奋斗。但也要考虑历史的进程。
    你写的这个工具啊, excited !刚好要用到!
    xhacker
        5
    xhacker  
       Feb 3, 2016
    `--ignore-existing` 和 `--ignore-(chinese|japanese|korean)` 似乎语义是反的?
    xhacker
        6
    xhacker  
       Feb 3, 2016
    另外:

    潇袆 李
    Xiāohuī Lǐ

    这是个 bug 么……
    Elethom
        7
    Elethom  
    OP
       Feb 3, 2016 via iPhone
    @xhacker

    --ignore-existing 是不再對已經標註過的聯繫人重新注音。

    查了一下這個條目,讀音並沒有標註錯。中文讀音來自 ICU ,多音字抓取自漢語字典。應該不會有錯。
    xhacker
        8
    xhacker  
       Feb 3, 2016
    @Elethom: 呃居然是我写错字了……了解了。
    xhacker
        9
    xhacker  
       Feb 3, 2016
    加 -k 参数就不干活了。似乎 https://github.com/Elethom/ContactsUtil-PhoneticName/blob/master/src/main.m#L107-L109 这里有点问题?
    ppwangs
        10
    ppwangs  
       Feb 3, 2016
    现在的孩子们连汉字都不认得了,需要注音了吗?
    Elethom
        11
    Elethom  
    OP
       Feb 3, 2016 via iPhone
    @xhacker
    暈。對不起,那一段應該向下移動一行。稍後起來改。 _(:з」∠)_
    imn1
        12
    imn1  
       Feb 3, 2016
    注音还是拼音?大陆这边懂注音的恐怕不多
    Elethom
        13
    Elethom  
    OP
       Feb 3, 2016 via iPhone
    @imn1
    這個也支援其它語言所以用「拼音」似乎不太合適。
    Elethom
        14
    Elethom  
    OP
       Feb 3, 2016
    @xhacker
    Repo 更新了。 Homebrew 待 merge 。
    https://github.com/Homebrew/homebrew/pull/48749
    Elethom
        15
    Elethom  
    OP
       Feb 3, 2016
    @xhacker

    $ brew audit contacts-phonetic --online
    contacts-phonetic:
    * GitHub repository not notable enough (<10 forks, <10 watchers and <20 stars)
    * GitHub repository too new (<30 days old)

    Error: 2 problems in 1 formula

    CI 失敗。 😭
    xhacker
        16
    xhacker  
       Feb 3, 2016
    @xhacker: 「 Ignore existing phonetic names. Use of this option will update all person entries in the address book.」你这两句话似乎是自相矛盾的?
    Elethom
        17
    Elethom  
    OP
       Feb 3, 2016
    @xhacker
    並沒有呀。忽略掉已經存在的 phonetic names 不就是不管原來有沒有全部都更新嗎。默認的話是會檢查是否存在的,存在即跳過。
    zander
        18
    zander  
       Feb 3, 2016
    Absolutely great job.
    几天前我还在那个帖子里提到日文名字的发音问题, LZ 行动力挺高的。

    不过 CFStringTokenizer 对日文支持不是很好,例如 相哲 soutetsu 就会认成 aiakira 。不过我也没找到更好的方法,就把项目搁置了。反正我添加联系人的机会也不多。
    won
        19
    won  
       Feb 3, 2016 via Android
    小爱桑好厉害哦
    Elethom
        20
    Elethom  
    OP
       Feb 3, 2016
    @zander
    嗯。 Core Foundation 的 tokenizer 也不能處理帶音調的日文,會直接展開。
    Elethom
        21
    Elethom  
    OP
       Feb 3, 2016
    @won
    f7u12 請叫「愛醬」。
    xhacker
        22
    xhacker  
       Feb 3, 2016
    @Elethom: 哦哦,这个意思……「 Ignore existing phonetic names 」我第一反应是忽略已经存在的名字不处理……
    Elethom
        23
    Elethom  
    OP
       Feb 3, 2016
    @xhacker
    怕前一句說不明白就在後面加了這句⋯⋯ 😭
    n6DD1A640
        24
    n6DD1A640  
       Feb 3, 2016
    @Elethom 直接删掉这句就行了,只要后面一句。。。参数改为 -a 。。
    blueset
        25
    blueset  
       Feb 6, 2016
    提个建议:
    关于 -i 的说明,可以改成 Overwrite existing phonetic names.

    顺便问一下,这个工具可以用于 Google Contact 吗?
    Elethom
        26
    Elethom  
    OP
       Feb 6, 2016
    @blueset
    未測試。在 Contacts app 中顯示出來的應該都可以。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6078 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 96ms · UTC 06:07 · PVG 14:07 · LAX 23:07 · JFK 02:07
    ♥ Do have faith in what you're doing.