   (c-route/resources "/"))
 
 
+(defn prep-rules-for-saving [rules-list]
+  (map
+   (fn [[k v]] {:name  k  :predicate (pr-str v)})
+   rules-list))
+
 (defn init [env]
   (db/init {:collection-name "rawdata"
             :db-name "spcr-db"
             :uri (if (= env :prod) heroku-mongo-connection-uri nil)})
+  (if (nil? (seq (get-rules)))
+    (db/save
+     (prep-rules-for-saving rule-predicate-forms)
+     "categoryrules"))
   (if (nil? (seq (get-data)))
     (import-file test-data)))
 

            (ring.middleware [multipart-params :as mp])
            [clojure.java.io :as io]
            [compojure.route :as c-route]
            [ring.server.standalone :as server]
            [ring.middleware.json :as ring-json]
            [spcr.parser :as parser]

  (->> (db/get-all "rawdata")
       (map #(dissoc % :_id))))

(defn get-rules []
  (->> (db/get-all "categoryrules")
       (map (fn [{name :name pred-fn :predicate}]
              [(keyword  name) (eval  (edn/read-string pred-fn))]))
       (into {})))

(defn get-labeled-data [] ;todo add a query mechanism to filter on labels
  (-> (get-data)
      (rule-engine (merge default-rules (get-rules)))))

(defn get-label-stats []
  (->> (get-labeled-data)
