/
count.clj
37 lines (29 loc) · 1 KB
/
count.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(require '[clojure.java.io :as io])
(defn is-alpha [ch]
(let [ptrn (re-pattern "[a-zA-Z ]*")]
(re-matches ptrn ch)))
(defn read-file-name [a]
(if (.exists (io/as-file a))
(slurp a)))
(defn text-to-map [text-file]
"return a text file with characters in map"
(let [char-map {}])
(map (fn [^Character c]
(let [key (keyword (clojure.string/lower-case c))]
)
(defn text-to-vector [text-file]
(let [char-vec []]
(map (fn [^Character c]
(let [key (keyword (clojure.string/lower-case c))
inc (key char-vec)]
(if (not (= inc nil))
(def char-vec (assoc key char-vec (+ inc 1)))
(def char-vec (assoc key char-vec 1))))) text-file)))
(println (text-to-vector "this is a test"))
(defn print-most-common [charmap]
(reduce-kv #(println %2 %1) {} charmap))
(defn main [file]
(if-let [text (read-file-name file)]
(print-most-common (text-to-vector text))
(println "error occurred reading file")))
(main "fire.txt")