Sentimentos de tweets quando ao lançamento do Falcon Heavy


In [ ]:
library(twitteR)
library(ROAuth)
library(httr)
library(plyr)
library(stringr)
library(tidytext)
library(readr)
library(dplyr)

In [ ]:
# parameters: api_key,api_secret,access_token,access_token_secret
setup_twitter_oauth('1', '2', 
                    '3', 
                    '4')

In [ ]:
tweets_falcon <- searchTwitter('#falconheavy', n=3000, lang='pt')

In [ ]:
head(tweets_falcon)

In [ ]:
df <- twListToDF(tweets_falcon)

In [ ]:
head(df)

In [ ]:
oplexicon <- read_csv('oplexicon_v3.0/lexico_v3.0.txt', col_names = c('word', 'type', 'weight', 'other'), col_types = 
  cols(
    word = col_character(),
    type = col_character(),
    weight = col_integer(), 
    other = col_character()
  ))
head(oplexicon)

In [ ]:
stopwords <- read_csv('portuguese-stopwords.txt', col_names = 'word')

In [ ]:
tweets <- df %>%
    unnest_tokens(word,text) %>%
    anti_join(stopwords,by="word") 
head(tweets)

In [ ]:
sentimentoTweets <- tweets %>%
    inner_join(oplexicon) %>%
    group_by(screenName) %>%
    summarize(peso = sum(weight, na.rm = TRUE))
head(sentimentoTweets)

In [ ]:
sum(sentimentoTweets$peso)

In [ ]:
mean(sentimentoTweets$peso)

In [ ]: