A brief example of using fast feedback of the Clojure REPL to find the most common word from the book, "The importance of being Ernest". Please note that Project Gutenberg now Gzip's the book texts and serves them over https. The code changes required are in the tutorial https://practical.li/clojure/simple-p...
Spacemacs is used with CIDER to start and connect to a Clojure REPL. To see the code in more detail, the results are pretty printed.
Transcript of the video
I am using my Clojure editor with a simple project, to find the most common word from a book.
The book is the importance of being earnest from project Gutenberg
I am slurping in the book from the website, which returns a single string of the entire book text
This string is a value bound to the name importance-of-being-earnest, so we can refer to it easily throughout the code
We want to eliminate the common English words, otherwise works such as a, the, to, may be the most common word.
Slurp is used to get the common English words from a text file, in CSV format
The result of that is passed to split, creating individual words
Which are put into a set to remove any duplicate words, as sets contain unique values
A function is defined to get the most common word, although most of the code is commented, so we can explore what each expression does.
This function is called, passing the book as an argument
The book is passed into re-seq, which uses a regular expression to create individual workds from the book text.
All our common English words are in lower case, so transform all the words in the book to match
Now we can remove the common English words
We have the book in a form where we can start counting how many times a word appears
Frequencies creates a new data structure with a count for each book
With the word as a key and the Frequence as a value.
Sort by the value to put the result of frequencies in order
And reverse the order so we see the biggest at the top.
Not surprisingly the results show the most common words are characters names from the book
On this page of the site you can watch the video online Cloure REPL driven development - a simple example with a duration of hours minute second in good quality, which was uploaded by the user Practicalli 14 October 2020, share the link with friends and acquaintances, this video has already been watched 3,837 times on youtube and it was liked by 63 viewers. Enjoy your viewing!