Created
March 20, 2015 19:09
-
-
Save msszczep/4b5409d5a256a0717585 to your computer and use it in GitHub Desktop.
Clojure exercise: Sentiment Scoring for Words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn sentiment-scorer [& maps] | |
(letfn [(sentiment-scorer-intermediate [m] | |
(let [words (-> (:c m) | |
(clojure.string/lower-case) | |
(clojure.string/replace #"[\.\!\@]" "") | |
(clojure.string/split #"\s+")) | |
rs (repeat (count words) [(:r m)])] | |
(apply hash-map (interleave words rs))))] | |
(let [intermediate-map (->> (apply map sentiment-scorer-intermediate maps) | |
(apply merge-with concat))] | |
(zipmap (keys intermediate-map) | |
(map #(/ (apply + %) (count %)) (vals intermediate-map)))))) | |
(sentiment-scorer [{:r 5 :c "This is awesome!"} | |
{:r 1 :c "This sucks...."}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment