gpt4 book ai didi

swift - Cocoa/Cocoa Touch/Foundation中如何自定义CFString音译

转载 作者:可可西里 更新时间:2023-11-01 02:16:39 25 4
gpt4 key购买 nike

我正在探索如何使用 CFStringTransformtransliterate texts in Hebrew我遇到了一些不一致的地方,比如本应发音不同的字母却以完全相同的方式书写,或者 Apple 算法未考虑的特殊情况。

Kaf (כּ → K) vs Khaf (כ → Ḵ)

  • כִּי(“因为”)

    let string = NSMutableString(string: "כִּי")
    CFStringTransform(string, nil, kCFStringTransformLatinHebrew, true)
    print(string) // prints "ki̇y"
  • שָׁכָחְתִּי(“我忘记了”)

    let string = NSMutableString(string: "שָׁכָחְתִּי")
    CFStringTransform(string, nil, kCFStringTransformLatinHebrew, true)
    print(string) // prints "şá̌káẖĕţi̇y" instead of "şá̌ḵáẖĕţi̇y"

虽然 כִּי 中的 kaf 在英语中发音为 K,而 שָׁכָֽחְתִּי 中的 khaf 发音为 loch Bach,通常音译为 CH、KH 或 Ḵ。但是,这两个字母都音译为 K。

Pei (פּ → P) vs Fei (פ → F)

  • 法老王

    let string = NSMutableString(string: "פַּרְעֹה")
    CFStringTransform(string, nil, kCFStringTransformLatinHebrew, true)
    print(string) // prints "pȧrĕʻòh"
  • יוֹסֵף(“约瑟夫”)

    let string = NSMutableString(string: "יוֹסֵף")
    CFStringTransform(string, nil, kCFStringTransformLatinHebrew, true)
    print(string) // prints "ywòsép" instead of "ywòséf"

虽然 פְַּעֹה 中的 pei 发音像 P 在英语中的发音(并相应地音译),而 יוֹסֵף 中的(尾随)fei 发音像 F (并相应地音译)。但是,两者都用 P 音译。

尾随辅音 pataḥ g'nuva

来自 Hebrew vocalization 上的文章在英文维基百科中:

A patach on a letters ח, ע, ה at the end of a word is sounded before the letter, and not after. Thus, נֹחַ (Noah) is pronounced /ˈno.ax/. This only occurs at the ends of words and only with patach and ח, ע, and הּ (that is, ה with a dot (mappiq) in it). This is sometimes called a patach ganuv, or "stolen" patach (more formally, "furtive patach"), since the sound "steals" an imaginary epenthetic consonant to make the extra syllable.

但是:

  • תַפּוּחַ(“苹果”)

    let string = NSMutableString(string: "תַפּוּחַ")
    CFStringTransform(string, nil, kCFStringTransformLatinHebrew, true)
    print(string) // prints "ţaṗẇẖa" instead of "ţaṗẇaẖ"

问:如何更改 CFStringTransform 的行为以解决这三种情况?

来自reference for CFMutableString ,我们看到 CFStringTransform 作为 transform: 参数

A CFString object that identifies the transformation to apply. For a list of valid values, see Transform Identifiers for CFStringTransform. On OS X v10.4 and later, you can also use any valid ICU transform ID defined in the ICU User Guide for Transforms.

来自 the documentation听起来 ICU 转换的规则足够灵活,可以自定义。甚至还有一个 rule editor可以从 their playground 访问,但是,虽然我找到了a Stack Overflow question处理切线相似的事情,我找不到针对 RTL 语言的明确记录的方法。

最佳答案

据我所知,通过在中文和日文中使用它,CFStringTransform 逐个标记地工作,而不是将单词作为一个整体(可能是多个标记长)考虑在内。因此,当需要考虑多个标记时,音译将受到限制/不正确。我希望我认为这也是您希伯来语问题的根源(请指教)是正确的。

我发现音译在这种情况下更加准确,方法是使用 CFStringTokenizer 对文本进行标记,然后使用 CFStringTokenizerCopyCurrentTokenAttribute()< 依次获取每个标记的拉丁语音译 方法。这方面的一个例子——我认为在 Objective C 中,尽管这种情况下的语法与 Swift 非常相似——给出了 here。 .

关于swift - Cocoa/Cocoa Touch/Foundation中如何自定义CFString音译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37685877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com