在 R 中查找 Twitter 俚语
Twitter slang look up in R
我正在编写一个 R 脚本来分析推文的情绪。我正在使用 twitteR 和 ROAuth 包根据一些搜索键获取推文 words.I 我正在使用下面的代码来实现这一点。
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 中找到一本可以帮助我实现这一目标的字典,但没有找到。有没有人知道任何这样的字典,如果没有,有人可以建议我解决这个问题的最好方法。
这里有一些有用的资源 -
您可以下载数据并将其用作字典或查询。不要忘记删除停用词并执行词干提取。
我正在编写一个 R 脚本来分析推文的情绪。我正在使用 twitteR 和 ROAuth 包根据一些搜索键获取推文 words.I 我正在使用下面的代码来实现这一点。
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 中找到一本可以帮助我实现这一目标的字典,但没有找到。有没有人知道任何这样的字典,如果没有,有人可以建议我解决这个问题的最好方法。
这里有一些有用的资源 -
您可以下载数据并将其用作字典或查询。不要忘记删除停用词并执行词干提取。