【问题标题】:remove emoticons in R using tm package使用 tm 包删除 R 中的表情符号
【发布时间】:2017-07-03 20:19:07
【问题描述】:

我正在使用 tm 包来清理 Twitter 语料库。但是,该包无法清理表情符号。

这是一个复制的代码:

July4th_clean <- tm_map(July4th_clean, content_transformer(tolower))
Error in FUN(content(x), ...) : invalid input 'RT ElleJohnson Love of country is encircling the globes ������������������ july4thweekend July4th FourthOfJuly IndependenceDay NotAvailableOnIn' in 'utf8towcs'

有人可以指出我使用 tm 包删除表情符号的正确方向吗?

谢谢,

路易斯

【问题讨论】:

  • 从您的示例中不清楚您希望消除什么。您是要消除包含多个连续标点符号(例如 :-) 和 (-_-) 的子字符串,还是要消除像 ☺ 和 ❀ 这样的奇数 Unicode 字符?
  • 你是对的。我还以为是???或类似的东西。
  • 我是 R 新手。你知道我怎么能检查那个特定的推文吗?我想你使用 [] 但不确定是函数还是代码的任何其他部分。
  • 嗨,G5W,表情符号是桃子和美国国旗。 ??????
  • 我正在尝试消除奇怪的 Unicode 字符。

标签: r sentiment-analysis tm emoticons


【解决方案1】:

您可以使用gsub 去除所有非ASCII 字符。

Texts = c("Let the stormy clouds chase, everyone from the place ☁  ♪ ♬",
    "See you soon brother ☮ ",
    "A boring old-fashioned message" ) 

gsub("[^\x01-\x7F]", "", Texts)
[1] "Let the stormy clouds chase, everyone from the place    "
[2] "See you soon brother  "                                  
[3] "A boring old-fashioned message"

详情: 您可以使用[ ] 在正则表达式中指定字符类。当类描述以^ 开头时,它表示所有除了这些字符。在这里,我指定了除字符 1-127 之外的所有内容,即除标准 ASCII 之外的所有内容,并且我指定它们应替换为空字符串。

【讨论】:

    【解决方案2】:

    你可以试试这个功能

    iconv(July4th_clean, "latin1", "ASCII", sub="")
    

    重复问题,see post

    【讨论】:

    • 嗨 Zeyad,我确实看到了那个,但犹豫使用它,因为代码与我使用的 tm 代码不同。我正在使用
    • 你应该在使用 tm 包之前运行它
    猜你喜欢
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多