Add a function to convert a count map to a reversed map.
This commit is contained in:
@@ -11,6 +11,16 @@
|
|||||||
(inc (get acc val 0))))
|
(inc (get acc val 0))))
|
||||||
{} text))
|
{} text))
|
||||||
|
|
||||||
|
(defn reverse-count-characters
|
||||||
|
"Convert a map of pairs to a map where the characters grouped by the count and a count is the key."
|
||||||
|
[count-map]
|
||||||
|
(reduce
|
||||||
|
(fn [acc [symbol count]]
|
||||||
|
(->> (conj (get acc count []) symbol)
|
||||||
|
(into [])
|
||||||
|
(assoc acc count)))
|
||||||
|
{} count-map))
|
||||||
|
|
||||||
(defn chi-squared-letter-statistic
|
(defn chi-squared-letter-statistic
|
||||||
"To calculate the frequency distribution of a letter."
|
"To calculate the frequency distribution of a letter."
|
||||||
[letter-count letter-frequence length-text]
|
[letter-count letter-frequence length-text]
|
||||||
|
|||||||
@@ -8,6 +8,13 @@
|
|||||||
(is (= {\a 2 \b 1}
|
(is (= {\a 2 \b 1}
|
||||||
(count-characters "aba")))))
|
(count-characters "aba")))))
|
||||||
|
|
||||||
|
(deftest reverse-count-characters-test
|
||||||
|
(testing "The symbols must be grouped as a vector and the count must be a key."
|
||||||
|
(are [count-map expected-map]
|
||||||
|
(= expected-map (reverse-count-characters count-map))
|
||||||
|
{\a 1 \b 2 \c 1} {1 [\a \c] 2 [\b]}
|
||||||
|
{\a 1 \b 2 \c 3} {1 [\a] 2 [\b] 3 [\c]})))
|
||||||
|
|
||||||
(deftest chi-squared-letter-statistic-test
|
(deftest chi-squared-letter-statistic-test
|
||||||
(testing "If the frequence of A is 0.1, the text length is 100 and contains 20 times, then the chi-squared is 10."
|
(testing "If the frequence of A is 0.1, the text length is 100 and contains 20 times, then the chi-squared is 10."
|
||||||
(is (= 10.0
|
(is (= 10.0
|
||||||
|
|||||||
Reference in New Issue
Block a user