    [clojure.string :as string]
    [clojure.tools.logging :as log]
    [compojure.core :as compojure :refer [GET PUT POST DELETE ANY]]
-   [dag_unify.core :refer [fail? fail-path-between get-in merge remove-false
-                           remove-matching-keys strip-refs unify]]
-   [hiccup.core :refer [html]]
-))
+   [dag_unify.core :refer [fail? fail-path-between get-in remove-false strip-refs unify]]
+   [hiccup.core :refer [html]]))
+
+(defn analyze
+  ([surface-form]
+   (analyze surface-form (:lexicon medium)))
+  ([surface-form lexicon]
+   (morph/analyze surface-form lexicon)))
 
 (defn generate
   ([]
-   (first (take 1 (engine/generate-all :top medium))))
+   (let [result (engine/generate :top medium)]
+     (conj {:surface (fo result)}
+            result)))
   ([spec]
-   (first (take 1 (engine/generate-all spec medium))))
+   (let [result (engine/generate spec medium)]
+     (conj {:surface (fo result)}
+            result)))
   ([spec model]
-   (first (take 1 (engine/generate-all spec model)))))
-
-(defn generate-all
-  ([spec]
-   (engine/generate-all spec medium))
-  ([spec model]
-   (engine/generate-all spec model)))
+   (let [result (engine/generate spec model)]
+     (conj {:surface (fo result)}
+           result))))
+
+(defn lookup [lexeme]
+  ((:lookup medium) lexeme))
 
 (defn parse
   ([string]

   (GET "/" request
        {:status 200
         :body (html/page "Italian Workbook" (workbook-ui request) request)
         :headers {"Content-Type" "text/html;charset=utf-8"}})

   (GET "/parse/" request
        {:status 200
         :body
         (let [debug (log/info (str "sending string to parser.."))]
           (str "" (html/tablize
                    (get-in (strip-refs (first (parse (get (get request :query-params) "string"))))
                            [:synsem :sem]))))
         :headers {"Content-Type" "text/html;charset=utf-8"}})

   (GET "/q/" request

                          (get (get request :query-params) "attrs"))
         :headers {"Content-Type" "text/html;charset=utf-8"}})
  ))

;; not sure why this is necessary: investigate why english/workbook.clj doesn't need it.
(def foo (count (take 1 (parse "io dormo"))))
