library(tidytext)
## Warning: package 'tidytext' was built under R version 3.6.3
get_sentiments("afinn")
## # A tibble: 2,477 x 2
##    word       value
##    <chr>      <dbl>
##  1 abandon       -2
##  2 abandoned     -2
##  3 abandons      -2
##  4 abducted      -2
##  5 abduction     -2
##  6 abductions    -2
##  7 abhor         -3
##  8 abhorred      -3
##  9 abhorrent     -3
## 10 abhors        -3
## # ... with 2,467 more rows
get_sentiments("bing")
## # A tibble: 6,786 x 2
##    word        sentiment
##    <chr>       <chr>    
##  1 2-faces     negative 
##  2 abnormal    negative 
##  3 abolish     negative 
##  4 abominable  negative 
##  5 abominably  negative 
##  6 abominate   negative 
##  7 abomination negative 
##  8 abort       negative 
##  9 aborted     negative 
## 10 aborts      negative 
## # ... with 6,776 more rows
get_sentiments("nrc")
## # A tibble: 13,901 x 2
##    word        sentiment
##    <chr>       <chr>    
##  1 abacus      trust    
##  2 abandon     fear     
##  3 abandon     negative 
##  4 abandon     sadness  
##  5 abandoned   anger    
##  6 abandoned   fear     
##  7 abandoned   negative 
##  8 abandoned   sadness  
##  9 abandonment anger    
## 10 abandonment fear     
## # ... with 13,891 more rows
library(janeaustenr)
## Warning: package 'janeaustenr' was built under R version 3.6.3
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(stringr)

tidy_books <- austen_books() %>%
  group_by(book) %>%
  mutate(linenumber = row_number(),
         chapter = cumsum(str_detect(
           text, regex("^chapter [\\divxlc]",
                       ignore_case = TRUE)))) %>%
  ungroup() %>%
  unnest_tokens(word, text)

nrc_joy <- get_sentiments("nrc") %>% 
  filter(sentiment == "joy")

tidy_books %>%
  filter(book == "Emma") %>%
  inner_join(nrc_joy) %>%
  count(word, sort = TRUE)
## Joining, by = "word"
## # A tibble: 303 x 2
##    word        n
##    <chr>   <int>
##  1 good      359
##  2 young     192
##  3 friend    166
##  4 hope      143
##  5 happy     125
##  6 love      117
##  7 deal       92
##  8 found      92
##  9 present    89
## 10 kind       82
## # ... with 293 more rows
library(tidyr)

jane_austen_sentiment <- tidy_books %>%
  inner_join(get_sentiments("bing")) %>%
  count(book, index = linenumber %/% 80, sentiment) %>%
  spread(sentiment, n, fill = 0) %>% 
  mutate(sentiment = positive - negative)
## Joining, by = "word"
library(ggplot2)

ggplot(jane_austen_sentiment, aes(index, sentiment, fill = book)) +
  geom_col(show.legend = FALSE) +
  facet_wrap(~book, ncol = 2, scales = "free_x")

pride_prejudice <- tidy_books %>% 
  filter(book == "Pride & Prejudice")

afinn <- pride_prejudice %>% 
  inner_join(get_sentiments("afinn")) %>% 
  group_by(index = linenumber %/% 80) %>% 
  summarise(sentiment = sum(value)) %>% 
  mutate(method = "AFINN")
## Joining, by = "word"
bing_and_nrc <- bind_rows(
  pride_prejudice %>% inner_join(get_sentiments("bing")) %>%     mutate(method = "Bing et al."), pride_prejudice %>% 
  inner_join(get_sentiments("nrc") %>% 
  filter(sentiment %in% c("positive", "negative"))) %>%
  mutate(method = "NRC")) %>%
  count(method, index = linenumber %/% 80, sentiment) %>%
  spread(sentiment, n, fill = 0) %>%
  mutate(sentiment = positive - negative)
## Joining, by = "word"
## Joining, by = "word"
bind_rows(afinn, 
          bing_and_nrc) %>%
  ggplot(aes(index, sentiment, fill = method)) +
  geom_col(show.legend = FALSE) +
  facet_wrap(~method, ncol = 1, scales = "free_y")

get_sentiments("nrc") %>% 
     filter(sentiment %in% c("positive", "negative")) %>% 
  count(sentiment)
## # A tibble: 2 x 2
##   sentiment     n
##   <chr>     <int>
## 1 negative   3324
## 2 positive   2312
get_sentiments("bing") %>% 
  count(sentiment)
## # A tibble: 2 x 2
##   sentiment     n
##   <chr>     <int>
## 1 negative   4781
## 2 positive   2005
bing_word_counts <- tidy_books %>%
  inner_join(get_sentiments("bing")) %>%
  count(word, sentiment, sort = TRUE) %>%
  ungroup()
## Joining, by = "word"
bing_word_counts
## # A tibble: 2,585 x 3
##    word     sentiment     n
##    <chr>    <chr>     <int>
##  1 miss     negative   1855
##  2 well     positive   1523
##  3 good     positive   1380
##  4 great    positive    981
##  5 like     positive    725
##  6 better   positive    639
##  7 enough   positive    613
##  8 happy    positive    534
##  9 love     positive    495
## 10 pleasure positive    462
## # ... with 2,575 more rows
bing_word_counts %>%
  group_by(sentiment) %>%
  top_n(10) %>%
  ungroup() %>%
  mutate(word = reorder(word, n)) %>%
  ggplot(aes(word, n, fill = sentiment)) +
  geom_col(show.legend = FALSE) +
  facet_wrap(~sentiment, scales = "free_y") +
  labs(y = "Contribution to sentiment",
       x = NULL) +
  coord_flip()
## Selecting by n

custom_stop_words <- bind_rows(tibble(word = c("miss"), 
                              lexicon = c("custom")), 
                               stop_words)

custom_stop_words
## # A tibble: 1,150 x 2
##    word        lexicon
##    <chr>       <chr>  
##  1 miss        custom 
##  2 a           SMART  
##  3 a's         SMART  
##  4 able        SMART  
##  5 about       SMART  
##  6 above       SMART  
##  7 according   SMART  
##  8 accordingly SMART  
##  9 across      SMART  
## 10 actually    SMART  
## # ... with 1,140 more rows
library(wordcloud)
## Warning: package 'wordcloud' was built under R version 3.6.3
## Loading required package: RColorBrewer
tidy_books %>%
  anti_join(stop_words) %>%
  count(word) %>%
  with(wordcloud(word, n, max.words = 100))
## Joining, by = "word"
## Warning in wordcloud(word, n, max.words = 100): miss could not be fit on page.
## It will not be plotted.

library(reshape2)
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
tidy_books %>%
  inner_join(get_sentiments("bing")) %>%
  count(word, sentiment, sort = TRUE) %>%
  acast(word ~ sentiment, value.var = "n", fill = 0) %>%
  comparison.cloud(colors = c("gray20", "gray80"),
                   max.words = 100)
## Joining, by = "word"

PandP_sentences <- tibble(text = prideprejudice) %>% 
  unnest_tokens(sentence, text, token = "sentences")

PandP_sentences$sentence[2]
## [1] "however little known the feelings or views of such a man may be on his first entering a neighbourhood, this truth is so well fixed in the minds of the surrounding families, that he is considered the rightful property of some one or other of their daughters."
austen_chapters <- austen_books() %>%
  group_by(book) %>%
  unnest_tokens(chapter, text, token = "regex", 
                pattern = "Chapter|CHAPTER [\\dIVXLC]") %>%
  ungroup()

austen_chapters %>% 
  group_by(book) %>% 
  summarise(chapters = n())
## # A tibble: 6 x 2
##   book                chapters
##   <fct>                  <int>
## 1 Sense & Sensibility       51
## 2 Pride & Prejudice         62
## 3 Mansfield Park            49
## 4 Emma                      56
## 5 Northanger Abbey          32
## 6 Persuasion                25
bingnegative <- get_sentiments("bing") %>% 
  filter(sentiment == "negative")

wordcounts <- tidy_books %>%
  group_by(book, chapter) %>%
  summarize(words = n())

tidy_books %>%
  semi_join(bingnegative) %>%
  group_by(book, chapter) %>%
  summarize(negativewords = n()) %>%
  left_join(wordcounts, by = c("book", "chapter")) %>%
  mutate(ratio = negativewords/words) %>%
  filter(chapter != 0) %>%
  top_n(1) %>%
  ungroup()
## Joining, by = "word"
## Selecting by ratio
## # A tibble: 6 x 5
##   book                chapter negativewords words  ratio
##   <fct>                 <int>         <int> <int>  <dbl>
## 1 Sense & Sensibility      43           161  3405 0.0473
## 2 Pride & Prejudice        34           111  2104 0.0528
## 3 Mansfield Park           46           173  3685 0.0469
## 4 Emma                     15           151  3340 0.0452
## 5 Northanger Abbey         21           149  2982 0.0500
## 6 Persuasion                4            62  1807 0.0343

The above code was taken from the book “Text Mining with R” referenced below.

References

Silge, Julia and Robinson, David. 2020. italicText Mining with Ritalic.https://www.tidytextmining.com/index.html.

Arnold, Taylor B. 2016. cleanNLP: A Tidy Data Model for Natural Language Processing. https://cran.r-project.org/package=cleanNLP.

Arnold, Taylor, and Lauren Tilton. 2016. coreNLP: Wrappers Around Stanford Corenlp Tools. https://cran.r-project.org/package=coreNLP.

Rinker, Tyler W. 2017. sentimentr: Calculate Text Polarity Sentiment. Buffalo, New York: University at Buffalo/SUNY. http://github.com/trinker/sentimentr.

Extension

I will apply the sentimentr package to the Sufjan Stevens album “Illinois”. I chose Sufjan as he is known for being a creative lyricist and I thought his lyrics could potentially be interesting to analyze.

With the lyrics imported, we can run some sentiment analysis.

# Clean the songs by converting to lower and removing punc
library(tm)
## Warning: package 'tm' was built under R version 3.6.3
## Loading required package: NLP
## 
## Attaching package: 'NLP'
## The following object is masked from 'package:ggplot2':
## 
##     annotate
tidy_songs <- songs %>% lapply(tolower) %>% lapply(str_replace_all, "[[:punct:]]", " ") %>% lapply(str_replace_all, "[\n]", " ") %>% lapply(removeWords, words = stopwords("en"))

sent <- data.frame()
terms <- data.frame()

library(sentimentr)
## Warning: package 'sentimentr' was built under R version 3.6.3
sent <- sentiment(unlist(tidy_songs))

terms <- unlist(tidy_songs) %>% extract_sentiment_terms() %>% select(-neutral)

terms$title <- songnames
sent$title <- songnames

library(kableExtra)
## Warning: package 'kableExtra' was built under R version 3.6.3
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
kable(sent)
element_id sentence_id word_count sentiment title
1 1 34 0.1886484 Concerning the UFO Sighting Near Highland, Illinois
2 1 213 0.4145392 Come On! Feel the Illinoise!
3 1 84 0.1854852 John Wayne Gacy, Jr
4 1 154 0.7091242 Jacksonville
5 1 99 0.5075441 Decatur, Or, Round of Applause For Your Stepmother!
6 1 170 0.3873173 Go! Chicago! Go! Yeah!
7 1 129 0.2905488 Casimir Pulaski Day
8 1 129 0.2641353 The Man Of Metropolis Steals Our Hearts
9 1 35 0.7352842 Prairie Fire That Wanders About
10 1 165 0.0918629 The Predatory Wasp Of The Palisades Is Out To Get Us!
11 1 207 -0.2571678 They Are Night Zombies!! They Are Neighbors!! They Have Come Back From The Dead!! Ahhhh!
12 1 50 -0.4666905 The Seer’s Tower
13 1 212 1.2877553 The Tallest Man, The Broadest Shoulders
kable(terms)
element_id sentence_id negative positive sentence title
1 1 c(“alien”, “mysterious”) c(“spirit”, “grow”, “grow”) revenant came couldn t imagine spirit three stars alien thing took form lebanon oh god flashing night sirens grow grow oh history involved mysterious shade took form incarnation three stars delivering signs dusting eyes Concerning the UFO Sighting Near Highland, Illinois
2 1 c(“infliction”, “cull”, “cull”, “imitation”, “degraded”, “lacking”, “cried”, “cried”, “ghost”, “regret”, “death”, “death”, “terror”, “superstitious”, “alone”, “alone”, “alone”, “alone”, “superstition”, “belated”, “belated”, “antiquated”, “antiquated”, “devil”, “devil”) c(“great”, “great”, “great”, “intentions”, “intentions”, “best”, “best”, “glory”, “united”, “united”, “united”, “patience”, “patience”, “celebrate”, “celebrate”, “celebration”, “white”, “adequate”, “soft”, “like”, “like”, “invented”, “covenant”, “progress”, “ancient”, “terrific”, “prolific”, “classical”, “devotion”, “promotion”, “new”, “amusement”, “treasure”, “optimistic”, “pleasures”, “improvise”, “laughed”, “level”, “level”, “right”) oh great intentions ve got best interventions ads come think now infliction entrepreneurial condition take us glory think now conversations cull united nations ve got patience celebrate ancients creation call celebration united nation put head oh great white city ve got adequate committee walls gone think now chicago fashion soft drinks expansion oh columbia paris incentive like cream wheat invented ferris wheel oh great intentions covenant imitation conscience think now oh god progress degraded forgot us laws gone think now ancient hieroglyphic south pacific typically terrific busy prolific classical devotion architect promotion lacking emotion think now chicago new age frank lloyd wright say oh columbia amusement treasure optimistic pleasures like ferris wheel conversations cull united nations ve got patience celebrate ancients columbia cried sleep last night ghost carl approached window hypnotized asked improvise attitude regret thousand centuries death even heart terror superstitious wearer riding alone writing alone even best condition counting superstition riding alone running alone laughed beatitudes thousand lines asked attitudes reminded us death even rest belated everything antiquated writing heart writing heart even heart devil know water level writing heart writing heart cried sleep last night earth materials may sound just right even rest belated everything antiquated writing heart writing heart even heart devil know water level writing heart writing heart Come On! Feel the Illinoise!
3 1 c(“cried”, “hit”, “rotting”, “dead”, “dead”, “dark”, “kill”) c(“adored”, “humor”, “fast”, “fast”, “like”, “like”, “clown”, “white”, “best”, “best”, “quiet”, “quiet”, “kiss”) father drinker mother cried bed folding john wayne s t shirts swingset hit head neighbors adored humor conversation look underneath house find living things rotting fast sleep dead twenty seven people even boys cars summer jobs oh god one dressed like clown face paint white red best behavior dark room bed kissed d kill ten thousand people sleight hand running far running fast dead took clothes put cloth lips quiet hands quiet kiss mouth best behavior really just like look beneath floorboards secrets hid John Wayne Gacy, Jr
4 1 c(“afraid”, “afraid”, “afraid”, “black”, “lost”, “dark”) c(“right”, “right”, “right”, “right”, “right”, “right”, “right”, “better”, “care”, “top”, “leads”, “medal”, “golden”, “spirit”, “spirit”, “spirit”, “spirit”, “nice”, “fine”, “fine”) m afraid black man running s got right s got better life comin don t care captain said fold right top head lost sight state packs follow heart leads right jackson oh keller oh oh oh oh gave us medal gave us map oh canner row oh oh oh seeing right look re m afraid nichol s park ride train ride dark m afraid get right turn around give one try said things meant say bandstand chairs dewey day parade go golden age spirit right spirit doesn t change oh keller oh oh oh oh gave us mirror gave us map oh canner row oh oh oh seeing right look re andrew jackson m asking show us wheel give us wine raise banner jackson hammer everyone goes capitol line colored preacher nice meet spirit spirit fine education ask nation gave us sight hearing fine andrew jackson m asking give us wheel give us wine Jacksonville
5 1 c(“hate”, “hate”, “wild”, “war”, “skeletons”, “smell”, “bad”, “abominate”) c(“lion”, “civil”, “spirit”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “congratulate”, “appreciate”, “appreciate”, “thank”, “thank”, “thank”, “thank”, “thank”) 1 2 3 4 stepmom everything hate took us edge decatur saw lion kangaroo take river caught wild alligator sangamon river overflowed caused mudslide banks operator civil war skeletons graves came clapping spirit aviator sound engines smell grain go riding abolition grain train stephen douglas great debater abraham lincoln great emancipator chickenmobile rooster tail fill know bad feels stay awake watch data small caterpillar go congratulate denominator go decatur go decatur s great abominate go decatur hate s great denominator go decatur anticipate s great appreciate appreciate stand thank stand thank s great stand thank s great stand thank s great stand thank Decatur, Or, Round of Applause For Your Stepmother!
6 1 c(“fell”, “mistakes”, “mistakes”, “mistakes”, “mistakes”, “mistakes”, “mistakes”, “mistakes”, “mistakes”, “mistakes”, “mistakes”, “crying”) c(“love”, “love”, “grow”, “grow”, “grow”, “grow”, “grow”, “grow”, “grow”, “grow”, “new”, “friend”, “friend”, “freedom”) fell love things go things go drove chicago things know things know sold clothes state don t mind don t mind made lot mistakes mind mind came take us things go things go recreate us things grow things grow mindset things know things know find things go things go drove new york van friend slept parking lots don t mind don t mind love place mind mind made lot mistakes mind mind came take us things go things go recreate us things grow things grow mindset things know things know find things go things go crying van friend freedom land made lot mistakes made lot mistakes made lot mistakes made lot mistakes came take us things go things go recreate us things grow things grow mindset things know things know find things go things go came take us things go things go recreate us things grow things grow mindset made lot mistakes things know things know made lot mistakes find made lot mistakes things go things go made lot mistakes Go! Chicago! Go! Yeah!
7 1 c(“cancer”, “cried”, “sorry”, “scared”, “crying”, “nurse”, “hung”) c(“found”, “found”, “found”, “prove”, “reading”, “glory”, “glory”, “glory”, “glory”, “study”, “pray”, “touched”, “top”, “great”, “finally”, “holiday”) 2 3 4 goldenrod 4h stone things brought found cancer bone father cried telephone drove car navy yard just prove sorry morning window shade light pressed shoulder blade see reading glory lord made complications without kissed mouth tuesday night bible study lift hands pray body nothing ever happens remember michael s house living room kissed neck almost touched blouse morning top stairs father found night told scared glory ran outside shirt tucked shoes untied told follow sunday night cleaned house found card wrote pictures mother floor great divide shirt tucked shoes untied crying bathroom morning finally go nurse runs head hung low cardinal hits window morning winter shade first march holiday thought saw breathing glory lord made complications see face morning window glory took place took shoulders shook face takes takes takes Casimir Pulaski Day
8 1 c(“trouble”, “falls”, “troubled”, “troubled”, “lies”, “unknown”, “dead”) c(“recover”, “gold”, “celebrate”, “celebrate”, “celebrate”, “celebrate”, “monument”, “golden”, “white”, “wise”, “lover”, “lover”, “lover”, “boy”) trouble falls home troubled man troubled stone turn mountain lies turn card life man steel man heart tame ways start devise something something half ways steel man came recover run gold carry celebrate sense lot give one another took bus lake saw monument face yellow tides golden eyes red white red wise raise flag summer home parted hair part unknown knew read ll send half ways real man can lover hands lend us celebrate sense lot give one another took bags illinois dreamt lake took boy man steel man heart turn ear part things said raise boat raise dead take us away still can say steel man can lover hands tremble celebrate sense lot give one another steel man can lover hands tremble celebrate sense lot give one another The Man Of Metropolis Steals Our Hearts
9 1 character(0) c(“infinity”, “divinity”, “hooray”, “great”, “faithfully”, “fun”) peoria destroyia infinity divinity lydia octavia jack trades cubs hooray opera house emma sang america oh will play santa clause great parade peoria made crossfire faithfully run middle america one one peoria saddle fun times Prairie Fire That Wanders About
10 1 c(“outrageously”, “creeping”, “tease”, “harm”, “tears”, “mistake”, “wait”, “wait”, “ghost”, “falling”, “swayed”, “terrible”, “terrible”, “terrible”, “terrible”, “sting”, “sting”, “storm”, “storm”, “wrestled”, “raged”) c(“fast”, “brother”, “best”, “best”, “friend”, “friend”, “friend”, “kiss”, “great”, “wonders”, “bright”, “trusting”, “love”, “love”, “love”, “love”, “hallelujah”, “admiration”) thinking outrageously write cursive hide bed lights floor wearing three layers coats leg warmers see breath face door oh quite sleeping oh fast bed wall bedroom creeping see wasp wings outstretched north savanna swim palisades come wearing brother s red hat shoulder best friend bit seven times runs washing face hands oh meant tease oh meant harm touching back hand kiss see wasp length arm oh great sights upon state hallelu wonders bright rivers lake hallelu trail tears horseshoe lake hallelu trusting things beyond mistake hallelu love love palisades palisades palisades can wait can wait lamb god sound horn hallelujah us ghost born hallelu can t explain state m state heart best friend car back seat oh admiration falling asleep powers day day can tell swaggered swayed deep tower prairies can tell telling gets old terrible sting terrible storm can tell day born friend gone ran away can tell love day though sparred wrestled raged can tell love day terrible sting terrible storm can tell The Predatory Wasp Of The Palisades Is Out To Get Us!
11 1 c(“grave”, “ghost”, “awakened”, “axe”, “dead”, “shake”, “shake”, “dirt”, “rust”, “nervous”, “nervous”, “lags”, “bite”, “death”, “topple”) c(“grant”, “community”, “save”, “praise”, “commemorate”, “helping”, “young”, “fast”, “chorus”, “guide”) l l n o s ring bell call write us l l n o s can call captain clitus logan grant ronald reagan grave xylophagan know ghost community sound horn address city will save dedicate will praise commemorate awakened axe night living dead last begun shake dirt wiping shoulders earth know know nations past know know rust last tremble nervous thought last forgot l l n o s ring bell call write us l l n o s can call captain clitus b u d caledonia s e c o r magnolia b r d s kankakee evansville parker city speaking names shake flag waking earth lifts lags see thousand rooms rest helping us taste bite death know know time passed m young m fast tremble nervous thought last forgot l l n o s ring bell call write us l l n o s can call captain clitus comer potato peelers g r e e n ridge reeders m c v e y horace e n o s start chorus corn farms tombs lemmon sailor springs things feminine centerville old metropolis shawneetown trade topple us l l n o s hold tongue don t divide us l l n o s land god hold guide us They Are Night Zombies!! They Are Neighbors!! They Have Come Back From The Dead!! Ahhhh!
12 1 c(“fire”, “wait”, “rips”, “rips”, “betrayed”, “grave”, “alone”) loved tower earth view reaches far see universe see fire see end seven miles earth emmanuel mothers sword robe comes dividing man brothers tower earth built emmanuel powers earth wait rips rips tower earth built emmanuel oh mother betrayed us father loved bathed us still go deepest grave go sleep alone The Seer’s Tower
13 1 c(“forgetfulness”, “fall”, “fall”, “battle”, “fortress”, “strain”, “fevers”, “fire”, “disaster”, “curse”, “ghost”, “envy”, “lost”, “mad”) c(“great”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “great”, “forgiving”, “forgiving”, “awe”, “gratefulness”, “patient”, “patient”, “patient”, “patient”, “spirit”, “spirit”, “spirit”, “volunteer”, “perfect”, “cornerstone”, “dream”, “spirits”, “grand”, “grateful”, “wise”, “sing”, “sing”, “heaven”, “master”, “protect”, “save”, “trumpet”, “better”, “king”, “celebrate”, “celebrate”, “new”) count days great frontier forgiving faced seventh year stand awe gratefulness can call forgetfulness call patient patient fall spirit carpenter invites us become america soldiers great frontier carpenter soldier one one s battle volunteer run friends ya run life friends ya american merica meri oh illinois illinois illi prairie frontier perfect farm s fortress faker cornerstone baker dancer fisher audition disher boxer fetcher ghweing gum dream catcher count days great frontier forgiving faced seventh year stand strain make ends meet five spirits grand marquee call patient patient fall spirit carpenter invites us man wall grateful us saw wise woman sing wasn t asking anything wasn t asking anything made nations sing become america soldiers great frontier run friends ya run life friends ya american merica meri oh illinois illinois illi mattress floozies actress movies lantern lotion wind wakes ocean standard edition architect s rendition fashion fevers house got sears oh great fire great disaster oh great heaven oh great master oh great goat curse gave us oh great ghost protect save us oh great river green envy oh jane addams spirit send thee oh great trumpet singers given lost better oh great goodman king swingers given made mad oh great bears bulls joe jackson celebrate celebrate new oh great illinois can start The Tallest Man, The Broadest Shoulders

Lets visualize the most positive and negative song to see if we can see the difference.

pos <- tidy_songs[[13]] %>% str_trim()
neg <- tidy_songs[[12]] %>% str_trim()

pos_tok <- pos %>% str_split('\\s+') %>% as.data.frame()
names(pos_tok) <- 'word'
neg_tok <- neg %>% str_split('\\s+') %>% as.data.frame()
names(neg_tok) <- 'word'

pos_tok %>% count(word) %>% with(wordcloud(word, n, min.freq = 1))

neg_tok %>% count(word) %>% with(wordcloud(word, n, min.freq = 1))

It becomes very clear why the song marked positive is positive. It has repetitive usage of the word great.

The negative song does appear to have a slightly more somber tone with words like rips, grave, and betrayed.

Here are the full songs.

print(songs[[13]])
## [1] "I count the days the Great Frontier\nForgiving, faced the seventh year\nI stand in awe of gratefulness\nI can and call forgetfulness\n\nAnd when I, and when I call\nThe Patient, the Patient fall\nThe Spirit, the Carpenter\nInvites us to be with her\n\nWhat have we become America?\nSoldiers on the Great Frontier!\nCarpenter and Soldier, one on one\nIt's the battle, volunteer!\n\nRun from yourself, from your friends, from ya--\nRun for your life, for your friends, for ya--\nAmerican, merica, meri--\nOh Illinois, Illinois, Illi--\n\nThe prairie, the frontier, the perfect farm, it's from here\nThe fortress, the faker, the cornerstone, the baker\nThe dancer, the fisher, audition and the disher\nThe boxer, the fetcher, the ghweing gum, dream catcher\n\nI count the days the Great Frontier\nForgiving, faced the seventh year\nI stand and strain to make ends meet\nFive Spirits on the Grand Marquee\n\nAnd when I, and when I call\nThe Patient, the Patient fall\nThe Spirit, the Carpenter\nInvites us to be with her\n\nThere was a man at the wall\nHe was grateful for us all\nI saw the Wise Woman sing\nShe wasn't asking anything\nShe wasn't asking anything\nHow she made the nations sing!\n\nWhat have we become America?\nSoldiers on the Great Frontier!\n\nRun from yourself,\nfrom your friends, from ya--\nRun for your life,\nfor your friends, for ya--\nAmerican, merica, meri--\nOh Illinois, Illinois, Illi--\n\nThe mattress, the floozies, the actress at the movies\nThe lantern, the lotion, the wind that wakes the ocean\nThe Standard Edition, the architect's rendition\nThe fashion, the fevers, the house we got at Sears\n\nOh Great Fire of Great Disaster\nOh Great Heaven, oh Great Master\nOh Great Goat, the curse you gave us\nOh Great Ghost, protect and save us\nOh Great River, green with envy\nOh Jane Addams, spirit send thee\nOh Great Trumpet and the singers\n(Given what you lost are you better off?)\nOh Great Goodman, King of Swingers\n(Given what you had, has it made you mad?)\nOh Great Bears and Bulls, Joe Jackson\n(Celebrate the few. Celebrate the new.)\nOh Great Illinois\n(It can only start with you)"
print(songs[[12]])
## [1] "In the tower above the earth,\nThere is a view that reaches far\nWhere we see the universe,\nI see the fire, I see the end.\n\nSeven miles above the earth,\nThere is Emmanuel of mothers.\nWith his sword, with his robe,\nHe comes dividing man from brothers.\n\nIn the tower above the earth, we built it for Emmanuel.\nIn the powers of the earth, we wait until it rips and rips.\nIn the tower above the earth, we built it for Emmanuel.\nOh my mother, she betrayed us, but my father loved and bathed us.\n\nStill I go to the deepest grave,\nWhere I go to sleep alone"