2017-12-06 4 views
1

텍스트와 이모티콘이 모두 포함 된 Facebook의 의견 세트 (Sprinkr와 같은 시스템을 통해 가져옴)가 있으며, R에서 다양한 분석을 실행하려고합니다. 이모티콘 문자를 정확하게 섭취하는 것이 어려워졌습니다.유니 코드 이모티콘을 R에 정확하게 입력하십시오.

예를 들어 :!?!?! 나는이 같은 것을 포함하는 메시지를 줄 것이다 (에 UTF-8 인코딩)를 .csv 있습니다

"이 올바른지를 그것이 사실이 아니라는 말 해주세요 내가 다른 소스에서 이해하는 것과,

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" 

지금, 나는 변환해야합니다! 우리 가족은 원래 Reeses 땅콩 버터 컵 "

그때 다음과 같은 방법으로 R로 섭취를 먹고 이 UTF-8을 ASCII로 변환 한 다음 다른 이모티콘 리소스와 연결하는 데 사용할 수 있습니다 (l 멋진 이케 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" 

내가 누락 된 부분을 밝히는 사람이 있습니까? 아니면 다른 이모티콘 매핑 리소스를 찾아야합니까? 감사!

+0

'dput (fb.comments $ message [5]) '를 표시 할 수 있습니까? –

+0

'''dput (fb.comments의 $ 메시지 [5]) 을 "이 올바른지!?!?! 그것이 사실이 아니라는 말 해주세요! 우리 가족은 원래 Reeses 땅콩 버터 컵을 먹는 <9f><92><9a><9f><92><9a> 0><9f><9a> \ n ""'' –

+0

그리고 mutate-iconv? –

답변

1

목표는 명확하지 않지만, 이모티콘을 올바르게 표시하고이를 바이트로 표시하는 것을 포기하는 것이 최선의 방법은 아니라고 생각합니다. 예를 들어 이모티콘을 설명으로 변환하려면 다음과 같이 할 수 있습니다.

x <- "IS THIS CORRECT!?!?! Please say it isn't true!!! Our family only eats the original Reeses Peanut Butter Cups" 

## read emoji info and get rid of documentation lines 
readLines("https://unicode.org/Public/emoji/5.0/emoji-test.txt", 
      encoding="UTF-8") %>% 
    stri_subset_regex(pattern = "^[^#]") %>% 
    stri_subset_regex(pattern = ".+") -> emoji 

## get the emoji characters and clean them up 
emoji %>% 
    stri_extract_all_regex(pattern = "# *.{1,2} *") %>% 
    stri_replace_all_fixed(pattern = c("*", "#"), 
          replacement = "", 
          vectorize_all=FALSE) %>% 
    stri_trim_both() -> emoji.chars 

## get the emoji character descriptions 
emoji %>% 
    stri_extract_all_regex(pattern = "#.*$") %>% 
    stri_replace_all_regex(pattern = "# *.{1,2} *", 
          replacement = "") %>% 
    stri_trim_both() -> emoji.descriptions 


## replace emoji characters with their descriptions. 
stri_replace_all_regex(x, 
         pattern = emoji.chars, 
         replacement = emoji.descriptions, 
         vectorize_all=FALSE) 

## [1] "IS THIS CORRECT!?!?! Please say it isn't true!!! Our family only eats the original Reeses Peanut Butter Cupsgreen heartgreen heartgreen heart" 
+0

이 정확히 목표였다. 고맙습니다. –

관련 문제