In our exploratory data analysis (EDA), we encounter text blobs in four distinct languages: German, English, Finnish, and Russian, represented by language codes de_DE, en_US, fi_FI, and ru_RU, respectively.

For each language, we are also given three types of text “blogs”, “news”, and “twitter”.

Due to limited computing resources, our EDA will focus exclusively on the analysis of blog text.

1. Cleaning the Blog Text

To initiate the analysis, we load the blog text into an R script and undertake a series of filtering and cleaning steps to extract more meaningful insights from our data.

The following function serves as our data cleaning mechanism. It performs both cleaning and tokenization on the blog text corresponding to the specific language code.

library(tidyverse, warn.conflicts=F, quietly=T)
library(tidytext, warn.conflicts=F, quietly=T)
library(tidyr, warn.conflicts=F, quietly=T)
library(wordcloud, warn.conflicts=F, quietly=T)

tokenize_language <- function(language_code, type) {
  path = sprintf('data/%s/%s.%s.txt', language_code, language_code, type)
  lines = read_lines(path)
  # convert to tibble by lines
  text_tibble <- tibble(text = lines)
  # separate into words tibble
  words_tibble <- text_tibble %>%
    separate_rows(text, sep = " ")
  # group by words, filter the stop words, then count the frequency
  tokens <- words_tibble %>%
    unnest_tokens(word, text) %>%
    anti_join(get_stopwords()) %>%
    count(word, sort = TRUE)
  return (tokens)
}

Here are the cleaning results from all language blogs:

Top 10 frequent words in German Blogs

german_tokens <- tokenize_language('de_DE', 'blogs')
## Joining with `by = join_by(word)`
print(german_tokens)
## # A tibble: 433,210 × 2
##    word       n
##    <chr>  <int>
##  1 und   376551
##  2 die   358543
##  3 der   278309
##  4 ich   227898
##  5 das   166974
##  6 zu    140765
##  7 ist   137765
##  8 nicht 129809
##  9 es    128982
## 10 den   121724
## # ℹ 433,200 more rows

Top 10 frequent words in English Blogs

english_tokens <- tokenize_language('en_US', 'blogs')
## Joining with `by = join_by(word)`
print(english_tokens)
## # A tibble: 319,833 × 2
##    word        n
##    <chr>   <int>
##  1 one    127287
##  2 just   100793
##  3 like   100442
##  4 can     98420
##  5 time    90918
##  6 get     71093
##  7 know    60496
##  8 now     60358
##  9 people  59574
## 10 also    55366
## # ℹ 319,823 more rows

Top 10 frequent words in Finnish Blogs

finnish_tokens <- tokenize_language('fi_FI', 'blogs')
## Joining with `by = join_by(word)`
print(finnish_tokens)
## # A tibble: 1,028,131 × 2
##    word       n
##    <chr>  <int>
##  1 ja    429303
##  2 että  150342
##  3 ei    144801
##  4 se     91748
##  5 mutta  85777
##  6 oli    75030
##  7 kun    69230
##  8 niin   64205
##  9 ole    61190
## 10 kuin   54827
## # ℹ 1,028,121 more rows

Top 10 frequent words in Russian Blogs

russian_tokens <- tokenize_language('ru_RU', 'blogs')
## Joining with `by = join_by(word)`
print(russian_tokens)
## # A tibble: 433,443 × 2
##    word       n
##    <chr>  <int>
##  1 и     333749
##  2 в     296610
##  3 на    159933
##  4 не    145556
##  5 что   106875
##  6 с     106777
##  7 я      83753
##  8 по     80206
##  9 а      69015
## 10 как    58306
## # ℹ 433,433 more rows

2. Data visualization with word cloud

Now we can display the text summary of each languages with word cloud:

German Blogs Word Cloud

wordcloud(german_tokens$word, german_tokens$n, max.words = 100)

English Blogs Word Cloud

wordcloud(english_tokens$word, english_tokens$n, max.words = 100)

Finnish Blogs Word Cloud

wordcloud(finnish_tokens$word, finnish_tokens$n, max.words = 100)

Russian Blogs Word Cloud

wordcloud(russian_tokens$word, russian_tokens$n, max.words = 100)

3. Conclusion

In the course of this Exploratory Data Analysis (EDA), we undertook the loading and cleaning of raw text files. Subsequently, we employed visualization techniques to present the top frequent words, culminating in a word cloud.

This comprehensive analysis enhances our understanding of the text data and sheds light on the most prominent words within the corpus.