NLP Project based on GutenbergR

The fist step of the project is the choosing the book and the author. My book is “We” by Zamiatin, Evgenii Ivanovich. “We” is a dystopian novel by Yevgeny Zamyatin, published in 1924. Set in a future society called the One State, it follows the protagonist, D-503, as he grapples with conformity and control in a highly regimented world. The story explores themes of totalitarianism, individuality, and the struggle for personal freedom in a surveillance-heavy society. It’s considered a pioneering work in the dystopian genre, influencing later classics like George Orwell’s “1984” and Aldous Huxley’s “Brave New World.”

We <-gutenbergr::gutenberg_download(61963, mirror = "http://mirrors.xmission.com/gutenberg/")

Frequency dictionary

Let’s build frequency dictionaries for words.

There are 3 steps:

  1. Tokenization and lower-case
  2. Stop-words removing (with anti-join function)
  3. Lemmatization
words_we <- dplyr::anti_join(unnest_tokens(We, word, text), stop_words)

words_we <- dplyr::mutate(words_we, lemma = lemmatize_words(word))

words_freq <- dplyr::count(words_we, lemma, sort=TRUE)

We can represent results in a wordcloud: This word-cloud was builded with wordcloud library. We can see the most frequency words in the book:

set.seed(1234)
wordcloud(words = words_freq$lemma, 
          freq = words_freq$n, 
          min.freq = 3,
          max.words = 100,
          random.order = FALSE,
          rot.per=0.35,
          colors= brewer.pal(5, "Set2")
          )

It is also possible to make the interactive wordcloud with the help of wordcloud2 library.

wordcloud2::wordcloud2(data = words_freq,
           minSize = 15,
           rotateRatio = 0,
           gridSize = 10,
          fontFamily = "Arial",
           shape = "circle",
           color = brewer.pal(5, "Set2"),
           backgroundColor = "white"
)