0
我正在寫一個R腳本來分析tweets的情緒。我正在使用twitteR和ROAuth包來獲取基於一些搜索關鍵詞的推文。我正在使用下面的代碼來實現此目的。Twitter俚語在R查找
library(twitteR)
library(ROAuth)
library(httr)
# Set API Keys
api_key <- "xxxxxx"
api_secret <- "yyyyyy"
acs_token <- "aaxxbbbb"
access_token_secret <- "xyyzziiassss"
setup_twitter_oauth(api_key, api_secret, acs_token, access_token_secret)
# Grab latest tweets
tweets_results <- searchTwitter('xfinity x1 netflix', n=1500)
# Loop over tweets and extract text
feed_results = lapply(tweets_results, function(t) t$getText())
現在我正在使用以下函數來清理推文。
clean_text = function(x)
{
x = gsub("rt", "", x) # remove Retweet
x = gsub("@\\w+", "", x) # remove at(@)
x = gsub("[[:punct:]]", "", x) # remove punctuation
x = gsub("[[:digit:]]", "", x) # remove numbers/Digits
x = gsub("http\\w+", "", x) # remove links http
x = gsub("[ |\t]{2,}", "", x) # remove tabs
x = gsub("^ ", "", x) # remove blank spaces at the beginning
x = gsub(" $", "", x) # remove blank spaces at the end
try.error = function(z) #To convert the text in lowercase
{
y = NA
try_error = tryCatch(tolower(z), error=function(e) e)
if (!inherits(try_error, "error"))
y = tolower(z)
return(y)
}
x = sapply(x, try.error)
return(x)
現在這個清理完成後有一定的嘰嘰喳喳的俚語(如「LUV的」,「BFF」,「BAE」等)。爲了進行有效的情感分析,這些俚語需要轉化爲標準的英語單詞。我希望能在R中找到一本能幫助我實現這一目標的字典,但沒有找到。是否有人知道任何這樣的詞典,如果沒有人能告訴我解決這個問題的最好方法。
http://www.netlingo.com/acronyms.php – hrbrmstr
您的代碼正在加載包,但您並未實際使用它。 –
@KonradRudolph感謝您的支持。我之前使用過它,但忘記刪除它。 – Venu