2013-04-01 63 views
17

我該如何處理/擺脫表情符號,以便我可以對推文進行情感分析?Twitter中的表情分析r的情感分析

獲取: 錯誤sort.list(Y): 無效輸入

感謝

,這是怎樣的表情出來,從Twitter和成R尋找:

\xed��\xed�\u0083\xed��\xed�� 
\xed��\xed�\u008d\xed��\xed�\u0089 
+3

嘗試工作的iconv() – ndoogan

+0

再看看'Encodings' –

+1

我可以建議你弄清楚這些編碼是什麼意思?表情符號是一種表達意義的語言形式,可能不會以正式的文本語言捕捉到。不知道你在追求什麼,但這些表情符號是情感,這是一種用典型的正式語言可能無法承受的方式表示姿勢/表情的方式。再次使用這裏的評論/解決方案不是爲了消除表情符號,而是要找出表情符號表達的意義。 –

回答

20

根據ndoogan的建議,這應該使用iconv擺脫表情符號。

一些重複性的數據:

require(twitteR) 
# note that I had to register my twitter credentials first 
# here's the method: http://stackoverflow.com/q/9916283/1036500 
s <- searchTwitter('#emoticons', cainfo="cacert.pem") 

# convert to data frame 
df <- do.call("rbind", lapply(s, as.data.frame)) 

# inspect, yes there are some odd characters in row five 
head(df) 

                                       text 
1                  ROFLOL: echte #emoticons [humor] http://t.co/0d6fA7RJsY via @tweetsmania ;-) 
2 「@teeLARGE: when tmobile get the iphone in 2 wks im killin everybody w/ emoticons &amp; \nall the other stuff i cant see on android!" \n#Emoticons 
3      E poi ricevi dei messaggi del genere da tua mamma xD #crazymum #iloveyou #emoticons #aiutooo #bestlike http://t.co/Yee1LB9ZQa 
4            #emoticons I want to change my name to an #emoticon. Is it too soon? #prince http://t.co/AgmR5Lnhrk 
5 I use emoticons too much. #addicted #admittingit #emoticons <ed><U+00A0><U+00BD><ed><U+00B8><U+00AC><ed><U+00A0><U+00BD><ed><U+00B8><U+0081> haha 
6                       What you text What I see #Emoticons http://t.co/BKowBSLJ0s 

以下是將消除表情重點線:

# Clean text to remove odd characters 
df$text <- sapply(df$text,function(row) iconv(row, "latin1", "ASCII", sub="")) 

現在再次檢查,看是否奇怪的字符都不見了(見第5行)

head(df)  
                                   text 
1                  ROFLOL: echte #emoticons [humor] http://t.co/0d6fA7RJsY via @tweetsmania ;-) 
2 @teeLARGE: when tmobile get the iphone in 2 wks im killin everybody w/ emoticons &amp; \nall the other stuff i cant see on android!" \n#Emoticons 
3      E poi ricevi dei messaggi del genere da tua mamma xD #crazymum #iloveyou #emoticons #aiutooo #bestlike http://t.co/Yee1LB9ZQa 
4            #emoticons I want to change my name to an #emoticon. Is it too soon? #prince http://t.co/AgmR5Lnhrk 
5                     I use emoticons too much. #addicted #admittingit #emoticons haha 
6                      What you text What I see #Emoticons http://t.co/BKowBSLJ0s 
+0

本 - 非常感謝你 - 清理它 - 最後! – Rhodo

+0

不客氣!如果你不熟悉,你應該積極回答,如果回答對你有用(這是在此表示感謝的首選方式)並點擊勾號(在向上/向下箭頭下)以表明這是對你的最佳答案題。這對其他與你具有相同問題的人有幫助(當有多個答案時,這個過程更加相關,在這種情況下,這更有趣)。 – Ben

+0

再次感謝 - 我是一個新手,我需要一個15的upvote。 – Rhodo

0

您可以使用正則表達式來判斷ct非字母字符並將其刪除。示例代碼:

rmNonAlphabet <- function(str) { 
    words <- unlist(strsplit(str, " ")) 
    in.alphabet <- grep(words, pattern = "[a-z|0-9]", ignore.case = T) 
    nice.str <- paste(words[in.alphabet], collapse = " ") 
    nice.str 
}