Saturday, April 30, 2016

Create a word frequency map out of a large string s

This most used operation which required for frequency map creation in data analysis
;; Create a word frequency map out of a large string s.

;; `s` is a long string containing a lot of words :)
(reduce #(assoc %1 %2 (inc (%1 %2 0)))
        {}
        (re-seq #"\w+" s))

; (This could be used as the `frequencies` function.)

(println 
(reduce #(assoc %1 %2 (inc (%1 %2 0)))
        {}
         (cartesian-pairs my-coll) )
)
 
Where (cartesian-pairs my-coll)  already  defined in prev. blog.

No comments: