Cyrillic transliteration in R

后端 未结 3 1580
无人共我
无人共我 2021-01-20 20:28

Are there packages for Cyrillic text transliteration to Latin in R? I need to convert data frames to Latin to use factors. It is somewhat messy to use Cyrillic factors in R.

相关标签:
3条回答
  • 2021-01-20 21:02

    It is possible to do it with stringi package as you above, but with different transform identifier, for Serbian latin:

    `stri_trans_general("жшчћђ", "Serbian-Latin/BGN")`
    

    All characters should be transformed correctly to Serbian latin.

    0 讨论(0)
  • 2021-01-20 21:06

    If afterwards one uses Base R to filter the data in Cyrillic, one get's all NA's, but if dplyr is used then everything is fine.

    0 讨论(0)
  • 2021-01-20 21:09

    I have found the package at last.

    > library(stringi)
    > stri_trans_general("женщина", "cyrillic-latin")
    

    [1] "ženŝina"

    > stri_trans_general("женщина", "russian-latin/bgn")
    

    [1] "zhenshchina"

    After that, the only issue remaining is the "ё" letter.

    > stri_trans_general("Ёж", "russian-latin/bgn")
    

    [1] "Yëzh"

    I had to remove all the "ё" letters

    > iconv(stri_trans_general("ёж", "russian-latin/bgn"),from="UTF8",to="ASCII",sub="")
    

    [1] "yzh"

    Or one can just remove the 'Ё' and 'ё' letters before

    > gsub('ё','e',gsub('Ё','E','Ёжики на ёлке'))
    

    [1] "Eжики на eлке"

    or after transliteration.

    0 讨论(0)
提交回复
热议问题