我該如何處理/擺脫表情符號,以便我可以對推文進行情感分析?Twitter中的表情分析r的情感分析
獲取: 錯誤sort.list(Y): 無效輸入
感謝
,這是怎樣的表情出來,從Twitter和成R尋找:
\xed��\xed�\u0083\xed��\xed��
\xed��\xed�\u008d\xed��\xed�\u0089
我該如何處理/擺脫表情符號,以便我可以對推文進行情感分析?Twitter中的表情分析r的情感分析
獲取: 錯誤sort.list(Y): 無效輸入
感謝
,這是怎樣的表情出來,從Twitter和成R尋找:
\xed��\xed�\u0083\xed��\xed��
\xed��\xed�\u008d\xed��\xed�\u0089
根據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 & \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 & \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
您可以使用正則表達式來判斷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
}
嘗試工作的iconv() – ndoogan
再看看'Encodings' –
我可以建議你弄清楚這些編碼是什麼意思?表情符號是一種表達意義的語言形式,可能不會以正式的文本語言捕捉到。不知道你在追求什麼,但這些表情符號是情感,這是一種用典型的正式語言可能無法承受的方式表示姿勢/表情的方式。再次使用這裏的評論/解決方案不是爲了消除表情符號,而是要找出表情符號表達的意義。 –