Skip to content

Instantly share code, notes, and snippets.

@practicalli-johnny
Created November 1, 2016 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save practicalli-johnny/05941171b7514e60102aa4fe026d73b6 to your computer and use it in GitHub Desktop.
Save practicalli-johnny/05941171b7514e60102aa4fe026d73b6 to your computer and use it in GitHub Desktop.
;; Book: The importance of being Earnest, Oscar Wilde
;; Source: Project Guttenburg (UTF-8 format)
(def importance-of-being-earnest
(slurp "http://www.gutenberg.org/cache/epub/844/pg844.txt"))
(def common-english-words
(set
(clojure.string/split
(slurp
"http://www.textfixer.com/resources/common-english-words.txt")
#",")))
(defn most-common-words [book]
(reverse
(sort-by val
(frequencies
(remove common-english-words
(map
#(clojure.string/lower-case %)
(re-seq #"[a-zA-Z0-9|']+" book)))))))
(most-common-words importance-of-being-earnest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment