使用tm包删除R中的表情 [英] remove emoticons in R using tm package

查看:131
本文介绍了使用tm包删除R中的表情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用tm软件包清理Twitter语料库.但是,该程序包无法清除表情符号.

I'm using the tm package to clean up a Twitter Corpus. However, the package is unable to clean up emoticons.

这是重复的代码:

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软件包删除表情符号吗?

Can someone point me in the right direction to remove the emoticons using the tm package?

谢谢

路易斯

推荐答案

您可以使用gsub摆脱所有非ASCII字符.

You can use gsub to get rid of all non-ASCII characters.

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以外的所有内容,并指定了应将它们替换为空字符串.

Details: You can specify character classes in regex's with [ ]. When the class description starts with ^ it means everything except these characters. Here, I have specified everything except characters 1-127, i.e. everything except standard ASCII and I have specified that they should be replaced with the empty string.

这篇关于使用tm包删除R中的表情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆