 (ns engulf.formulas.markov-requests
-  "Support for generating markov chains of requests"
+  "Support for generating markov chains of requests."
+  ;; TODO: This file's a bit of a messy in terms of organization and naming
   (:use clojure.pprint
         [clojure.string :only [lower-case]]
         [clojure.walk :only [keywordize-keys]])

                 tuples)]
    ;; loop the end to the front to finish it
    (-> counted
        (update-in [(.hashCode last-edge) (.hashCode first-edge)] incr-or-one)
        (update-in [(.hashCode last-edge) :total] incr-or-one))))

(defn counted-probabilities
  [counted]
  (map
   (fn [[request edges]]
     [request
      (reduce (fn [m [ereq ecount]]
                (if (= ereq :total)
                  m
                  (assoc m ereq (float (/ ecount (:total edges))))))
              {}
              edges)])
   counted))

(defn compile-preprocessed
  "Compiles a preprocessed corpus into a format suitable for the (chain) method"
  [{:keys [requests counted]}]
  (let [probabilities (counted-probabilities counted)]
    {:requests requests
     :request-keys (vec (filter #(not= :total %) (keys requests)))
     :transitions (compile-transitions probabilities)}))

(defn parse

     :counted counted}))

(defn corpus-chain
  "Takes an array of requests, returns a lazy seq of the chain"
  [corpus]
  (-> corpus
      preprocess-corpus
