1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Natural Language Processing in R

Exercise

Sentiment scores

In the book Animal Farm, three main pigs are responsible for the events of the book: Napoleon, Snowball, and Squealer. Throughout the book they are spreading thoughts of rebellion and encouraging the other animals to take over the farm from Mr. Jones - the owner of the farm.

Using the sentences that mention each pig, determine which character has the most negative sentiment associated with them. The sentences tibble contains a tibble of the sentences from the book Animal Farm.

Instructions

100 XP
  • Use the grepl() function to filter to sentences mentioning just the pigs name.
  • Using an inner_join(), join the sentiment score from the afinn lexicon.
  • Summarize the results by summing the score column.