Published
Edited
Jun 12, 2021
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
livro = await FileAttachment("machado_de_assis_esaú_e_jacob.txt").text();
Insert cell
Insert cell
typeof(livro)
Insert cell
livro.length
Insert cell
Insert cell
livro_start = livro.indexOf("CAPITULO PRIMEIRO")
Insert cell
livro_end = livro.indexOf("ÍNDICE")
Insert cell
Insert cell
livro.slice(livro_start-20, livro_start+30)
Insert cell
livro.slice(livro_end-20, livro_end+20)
Insert cell
Insert cell
livro_cortado = livro.slice(livro_start,livro_end-1)
Insert cell
Insert cell
"abcdefgh".slice(-3)
Insert cell
livro_cortado.slice(-120)
Insert cell
Insert cell
"iverton, dan, alexandre".split(", ")
Insert cell
livro_cortado.split(/CAPITULO/)
Insert cell
Insert cell
livro_cortado.replace("CAPITULO PRIMEIRO","CAPITULO I").slice(0,100)
Insert cell
livro_split = livro_cortado
.replace("CAPITULO PRIMEIRO","CAPITULO I")
.split("CAPITULO")
.slice(1) // remove a 1a linha vazia
Insert cell
Insert cell
chapter_word_count=livro_split.map(c=>chapter_words(c).length)
Insert cell
viewof words_per_chapter = aq.table({word_count:chapter_word_count})
.derive({chapt:op.row_number()},{before:0})
.view({height:240})
Insert cell
vl.markBar()
.data(words_per_chapter)
.encode(
vl.x().fieldQ("chapt").scale({domain:[0,120]}),
vl.y().fieldQ("word_count")
)
.width(500)
.render()
Insert cell
Insert cell
cap_01_words = chapter_words(livro_split[0])
Insert cell
Insert cell
Insert cell
stop_words = aq.fromCSV(await FileAttachment("machado_stopwords.csv").text())
Insert cell
stop_words
.view({height:240})
Insert cell
Insert cell
viewof cap_01_word_freq_ns = cap_01_word_freq
.antijoin(stop_words,['word','palavra'])
.view({height:240})
Insert cell
vl.markBar()
.data(cap_01_word_freq_ns.slice(0,10))
.encode(
vl.y().fieldN("word").sort(d=>d.count),
vl.x().fieldQ("count")
)
.render()
Insert cell
Insert cell
positive_words = aq.fromCSV(await FileAttachment("sentimentos_positivos@1.csv").text())
Insert cell
negative_words = aq.fromCSV(await FileAttachment("sentimentos_negativos@1.csv").text())
Insert cell
positive_words.view({height:240})
Insert cell
negative_words.view({height:240})
Insert cell
md`### 9.1 Usando semi-join, reporta palavras positivas e negativas no primeiro capítulo`
Insert cell
cap_01_word_freq_ns
.semijoin(positive_words,['word','palavra'])
.view({height:240})
Insert cell
cap_01_word_freq_ns
.semijoin(negative_words,['word','palavra'])
.view({height:240})
Insert cell
Insert cell
get_sentiment(livro_split[0])
Insert cell
Insert cell
livro_sentimentos=livro_split.map(c=>get_sentiment(c).sentiment);
Insert cell
livro_sentimentos_table=aq.table({sentimento:livro_sentimentos})
.derive({chapter:op.row_number()},{before:0})
.derive({is_positive:d=>d.sentimento>0})
Insert cell
livro_sentimentos_table
.view({height:240})
Insert cell
vl.markBar()
.data(livro_sentimentos_table)
.encode(
vl.x().fieldQ("chapter").scale({domain:[0,120]}),
vl.y().fieldQ("sentimento"),
vl.color().fieldN("is_positive").scale({range:['red','green']}).legend(null)
)
.width(500)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
heroku_cors = "https://puc-mdt-cors.herokuapp.com/"
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more