我有一组来自 Facebook 的评论(通过 Sprinkr 等系统拉取),其中包含文本和表情符号,我尝试在 R 中对它们进行各种分析,但在正确提取表情符号字符方面遇到了困难。
例如:我有一个 .csv(以 UTF-8 编码),其消息行包含如下内容:
“这是正确的吗?!?!请说这不是真的!!!我们家只吃原味的里斯花生酱杯????????????”
然后我通过以下方式将其引入 R 中:
library(tidyverse)
library(janitor)
raw.fb.comments <- read_csv("data.csv",
locale = locale(encoding="UTF-8"))
fb.comments <- raw.fb.comments %>%
clean_names() %>%
filter(senderscreenname != "Reese's") %>%
select(c(message,messagetype,sentiment)) %>%
mutate(type = "Facebook")
fb.comments$message[5]
[1] "IS THIS CORRECT!?!?! Please say it isn't true!!! Our family only eats the original Reeses Peanut Butter Cups\xf0\u009f\u0092\u009a\xf0\u009f\u0092\u009a\xf0\u009f\u0092\u009a\n\n"
现在,根据我从其他来源了解到的情况,我需要将这个 UTF-8 转换为 ASCII,然后我可以用它来将它与其他表情符号资源链接起来(比如精彩的表情符号资源)表情符号词典 https://github.com/lyons7/emojidictionary)。为了使连接工作,我需要将其转换为 R 编码,如下所示:
<e2><9d><a4><ef><b8><8f>
但是,添加正常步骤(使用iconv
)没有让我到达那里:
fb.comments <- raw.fb.comments %>%
clean_names() %>%
filter(senderscreenname != "Reese's") %>%
select(c(message,messagetype,sentiment)) %>%
mutate(type = "Facebook") %>%
mutate(message = iconv(message, from="UTF-8", to="ascii",sub="byte"))
fb.comments$message[5]
[1] "IS THIS CORRECT!?!?! Please say it isn't true!!! Our family only eats the original Reeses Peanut Butter Cups<f0><9f><92><9a><f0><9f><92><9a><f0><9f><92><9a>\n\n"
任何人都可以向我阐明我所缺少的内容,或者我是否需要找到不同的表情符号映射资源?谢谢!