dsdt66064367 2013-11-06 14:19
浏览 71
已采纳

组合或构造韩文字母

Is there anyway that I can combine this Korean consonants and vowels into a complete character.

For example if I have

  ㄱㅏㅁㅅㅏㅎㅏㅂㄴㅣㄷㅏ

It would be

  감사합니다

Is there any way to do this? I can only think of bruteforcing every case that would have to count many many cases.

Below is my try. Not optimal and take too much time.

if strings.Contains(input_str, "ㅏㄴㅈ") {
    input_str = strings.Replace(input_str, "ㅇㅏㄴㅈ", "앉", -1)
}

if strings.Contains(input_str, "ㅏㄹㅂ") {
    input_str = strings.Replace(input_str, "ㅂㅏㄹㅂ", "밟", -1)
}

if strings.Contains(input_str, "ㅏㅂㅅ") {
    input_str = strings.Replace(input_str, "ㄱㅏㅂㅅ", "값", -1)
}
  • 写回答

2条回答 默认 最新

  • douzhao4071 2013-11-06 15:58
    关注

    What you want is Unicode normalization to compose hangul jamo. Go supports this but not (yet) in the standard library. See this related issue.

    To import the external go.text/unicode/norm package use:

    go get -u golang.org/x/text/unicode/norm
    

    You probably want to use NFC which does a

    • Canonical Decomposition,
    • followed by Canonical Composition (which is what you want)

    Example for NFD (decomposition):

    // 앉 -> 앉
    fmt.Println( string( norm.NFD.AppendString(nil, "앉") ) )
    

    Example for NFC (composition):

    // 앉 -> 앉
    fmt.Println( string( norm.NFC.AppendString(nil, "앉") ) )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置