QUANTITATIVE TEXT ANALYSIS

Quanteda e syuzhet

Renato Barreira

OBJETIVO

  • Objetivo: Análise exploratória de entrevistas de profundidade sobre questões políticas;

  • Banco de Dados: Próprio.

QUANTEDA

Benoit K, Watanabe K, Wang H, Nulty P, Obeng A, Müller S, Matsuo A (2018). “quanteda: An R package for the quantitative analysis of textual data.” Journal of Open Source Software, 3(30), 774. doi:10.21105/joss.00774, https://quanteda.io.

Abrinco o banco de dados e pré processamento

require(readtext)
require(quanteda)
require(quanteda.textstats)
require(quanteda.textplots)
require(quanteda.textmodels)

rx = readtext('*.txt')
rx
readtext object consisting of 2 documents and 0 docvars.
# A data frame: 2 × 2
  doc_id                   text               
  <chr>                    <chr>              
1 a favor do bolsonaro.txt "\"Então eu t\"..."
2 contra bolsonaro.txt     "\"Realmente \"..."

Abrinco o banco de dados e pré processamento

x=corpus(rx)
tx = tokens(x, remove_punct = T,
                 remove_symbols = T,
                 remove_numbers = T,
                 remove_url = T,
                 remove_separators = T)
tx = tokens_remove(tx, stopwords('pt'))
tx = tokens_tolower(tx)
extra = c('é', 'tá', 'acho', 'assim', 'porque', 'fazer', 'vai', 'então', 'coisa', 'aí',
          'fazendo', 'votei', 'pra', 'lá', 'pode', 'falar', 'nele', 'ser', 'né',
          'coisas', 'cara', 'gente', 'entendeu', 'pô', 'pro', 'mim'
          )
tx = tokens_remove(tx, extra)
dx = dfm(tx) # document-feature matrix
topfeatures(dx)
presidente    governo    pessoas  bolsonaro   pandemia       tudo       país 
        28         26         24         21         21         21         19 
   opinião         pt        bom 
        18         18         17 

Nuvem de Palavras

textplot_wordcloud(dx,min_size = 2,
                   min_count = 10,
                   color = rainbow(1),
                   comparison = T)

“Keyness”

keydtx = textstat_keyness(dx)
textplot_keyness(keydtx)

Posição relativa

wfx = textmodel_wordfish(dx, c(1,2))
textplot_scale1d(wfx)

Análise de Sentimentos com Syuzhet

require(syuzhet)
sx = get_nrc_sentiment(x, lang="portuguese")
rownames(sx)=x$doc_id
sx
  anger anticipation disgust fear joy sadness surprise trust negative positive
1    34           27      26   37  26      55       17    45       91       68
2    13            6      15   21   4      24        4    19       53       29

Análise de Sentimentos com Syuzhet

Colab aqui

Muito Obrigado

Aprendizado Profundo - Prof. Pedro - PPGI