-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_mukeka.R
91 lines (56 loc) · 1.97 KB
/
script_mukeka.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# bibliotecas -------------------------------------------------------------
#dados
library(tidyverse)
#api vagalume
library(vagalumeR)
#mineracao de texto
library(tidytext)
library(stopwords)
#nuvem
library(wordcloud)
# chave api ---------------------------------------------------------------
usethis::edit_r_environ(scope = "project")
api_key <- Sys.getenv("API_VAGALUME")
# artista -----------------------------------------------------------------
artist <- "mukeka-di-rato"
# informacoes do artista --------------------------------------------------
# informacoes no vagalume
artist_info <- artist |>
map_dfr(artistInfo)
# musicas
songs_artist <- artist |>
map_dfr(songNames)
# amostra de musicas do artista -------------------------------------------
set.seed(1)
songs_sample <- songs_artist |>
sample_n(60) |> #amostra de 60 musicas
pull(song.id) |> #coluna de ids das musicas
map_dfr(
vagalumeR::lyrics, #retorna as letras das musicas
artist = "Mukeka di Rato", #nome como aparece no site vagalume
type = "id", key = api_key,
message = FALSE
)
# mineracao de texto ------------------------------------------------------
# stopwords
sw <- c(
stopwords::stopwords("pt"),
c("é", "ta", "la", "tá", "lá", "to", "el", "in", "pra", "and",
"il", "in", "i", "3x", "2x", "of", "x", "the", "is")
)
# letras das musicas
lyrics <- songs_sample |>
select(text)
# contagem das palavras
count_words <- tibble(text = lyrics$text) |> #transforma cada musica em uma observacao
tidytext::unnest_tokens(word, text, to_lower = TRUE) |> #transforma cada palavra em uma observacao
count(word, sort = TRUE) |> #frequencia de cada palavra
anti_join(tibble(word = sw)) #remove as palavras stopwords
# nuvem de palavras -------------------------------------------------------
wordcloud(
count_words$word, count_words$n,
max.words = 100,
colors = c("red", "blue", "black"),
random.order = FALSE,
scale = c(2, .5), rot.per = 0.35,
)