   (:use [clojure.pprint :only [pprint]])
   (:require [clojure.tools.logging :as log]
             [clojure.string :as str])
+  (:require [zensols.tabres.display-results :as dr])
   (:require [zensols.actioncli.resource :refer (resource-path)]
             [zensols.model.classifier :as cl]
             [zensols.model.weka :as weka]))

  [model & data]
  (log/debugf "classifying: %s" data)
  (with-model-conf (:model-conf model)
    (let [{classifier :classifier
           feature-metas :feature-metas
           ;; this was the context that was persisted with the model
           context :context} model
          _ (log/tracef "context: <%s>" context)
          model-conf (model-config)
          trans-fn (or (:classifications-map-fn model-conf) identity)
          create-features-fn (or (:create-features-fn model-conf)
                                 (throw (ex-info "No create-features-fn defined in model"
                                                 {:model-name (:name model-conf)})))
          _ (log/debugf "create-features-fn: %s" create-features-fn)
          cfargs (concat data (list context))
          _ (log/debugf "arg count: %d" (count cfargs))
          features (apply create-features-fn cfargs)
          ;; must use copy constructor or it gives bad results
          instances (weka/clone-instances (:instances model))
          attribs (map name feature-metas)
          return-keys (:model-return-keys model-conf)]
      (set-instance-values (.instance instances 0) features)
      (->> (cl/classify-instance classifier instances return-keys)
           first
           (merge (if (contains? return-keys :features) {:features features}))
           trans-fn ))))

                                     :attrib attrib}
                                e)))))))))

(defn- classify-features
  "Classify a single instance using a trained model.

  * **model** a model created
  from [[zensols.model.eval-classifier/train-model]] or [[read-model]]"
  [model features]
  (log/debugf "classifying features: %s" features)
  (with-model-conf (:model-conf model)
    (let [{classifier :classifier
           feature-metas :feature-metas} model
          model-conf (model-config)
          trans-fn (or (:classifications-map-fn model-conf) identity)
          ;; must use copy constructor or it gives bad results
          instances (weka/clone-instances (:instances model))
          attribs (map name feature-metas)
          return-keys (:model-return-keys model-conf)]
      (log/tracef "instances: %s" (type instances))
      (set-instance-values (.instance instances 0) features)
      (->> (cl/classify-instance classifier instances return-keys)
           first
           (merge (if (contains? return-keys :features) {:features features}))
           trans-fn))))

(defn classify
  "Classify a single instance using a trained model.

