代码之家  ›  专栏  ›  技术社区  ›  Scott

在R中转换表情文字

  •  3
  • Scott  · 技术社区  · 7 年前

    createCorpus <- function(corpusData){
        aCorpus <- Corpus(DataframeSource(corpusData))
        ...
        aCorpus <- tm_map(aCorpus,content_transformer(tolower))
    }
    

    真实的 文本

    “utf8towcs”

    现在,我尝试添加 str_replace_all(aCorpus$content,"[^[:graph:]]", " ") 按照中的建议转换为小写 this answer 。这会产生与上述完全相同的错误,几乎就像它实际上没有做任何事情一样。

    我也试过了 tm_map(aCorpus, function(x) iconv(enc2utf8(x), sub = "byte")) here ,这会产生错误:

    enc2utf8(x)中出错:参数不是字符向量

    str_replace_all() 这是正确的方法,但我一定做错了什么?如何删除所有表情符号,以便清理语料库?

    编辑

    1 回复  |  直到 7 年前
        1
  •  4
  •   Scott    7 年前

    tm_map(aCorpus, function(x) iconv(enc2utf8(x$content), sub = "byte"))
    

    tm_map(aCorpus, function(x) iconv(enc2utf8(x), sub = "byte"))
    

    x$content 作为参数,而不仅仅是 x .