首页 文章

推特俚语抬头看着R

提问于
浏览
0

我正在写一个R脚本来分析推文的情绪 . 我正在使用twitteR和ROAuth包来根据一些搜索关键词得到推文 . 我使用下面的代码来实现这一点 .

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)

在完成这个清理之后,有一些Twitter俚语(如“Luv”,“BFF”,“BAE”等) . 为了进行有效的情感分析,这些俚语需要转换为标准的英语单词 . 我希望在R中找到一本可以帮助我实现这一目标的字典,但是没有找到 . 有没有人知道任何这样的字典,如果没有人可以建议我解决这个问题的最佳方法 .

1 回答

  • 2

    这里有一些有用的资源 -

    您可以下载数据并将其用作字典或查找 . 不要忘记删除停用词并执行词干 .

相关问题