Skip to content

Instantly share code, notes, and snippets.

@MichaelDrogalis
Created May 4, 2012 20:40
Show Gist options
  • Select an option

  • Save MichaelDrogalis/2597592 to your computer and use it in GitHub Desktop.

Select an option

Save MichaelDrogalis/2597592 to your computer and use it in GitHub Desktop.
(use '[clojure.string :only (split-lines split)])
(defn read-lines [args]
{ :lines (split-lines (slurp (:filename args))) })
(defn lines-to-words [args]
{ :words (map #(split % #"\s") (:lines args)) })
(defn words-to-freqs [args]
{ :word-freqs (map #(frequencies %) (:words args)) })
(defn merge-freqs [args]
{ :freqs (apply merge-with + (:word-freqs args)) })
(merge-freqs
(words-to-freqs
(lines-to-words
(read-lines { :filename "data.txt" }))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment