   [:require
    [babel.directory :refer [models]]
    [babel.generate :refer [generate]]
-   [babel.korma :as korma]
+   [babel.korma :as korma :refer [convert-keys-from-string-to-keyword init-db]]
    [clojure.string :as string]
    [clojure.data.json :as json :refer [read-str write-str]]
    [clojure.tools.logging :as log]
    [compojure.core :as compojure :refer [GET PUT POST DELETE ANY]]
-   [dag_unify.core :as unify :refer [deserialize dissoc-paths get-in ref? strip-refs unify]]
+   [dag_unify.core :as unify :refer [dissoc-paths get-in ref? strip-refs unify]]
    [korma.core :as db]])
 
 ;; Configure database's 'expression' table to find the expressions.

                   (str "SELECT surface FROM expression WHERE language='" language "' AND structure @> "
                        "'" json-spec "'")))

    (let [results (db/exec-raw [(str "SELECT serialized::text 
                                        FROM expression 
                                       WHERE language=? 
                                         AND active=true

                        (let [sql (str "SELECT surface FROM expression_with_root AS source WHERE "
                                       " source.structure->'synsem'->'sem' @> '" json-source-semantics "'")
                              message (str "no source expression found for target semantics: "
                                           (get-in target-structure
                                                   [:synsem :sem])
                                           "; used source semantics:" source-semantics "; SQL:" sql)]
                          (log/error message)
                          (throw (Exception. message))))
                      {:source-id (first (map :source_id results))
                       :source (first (map :source results))
                       :target-spec target-spec
                       :targets-with-roots (map (fn [result]
                                                  {:root (:target_root result)
                                                   :target (:target result)})
                                                results)
                       :targets (map :target results)})))))))))
    
(defn get-lexeme [canonical language & [ spec ]]
  "get a lexeme from the database given the canonical form, given a
  language and optionally additional filter specification"
  ;; TODO: does not support filter yet.
  (let [results (db/exec-raw [(str "SELECT structure
                                      FROM lexeme
                                     WHERE canonical=?
                                       AND language=?")
                              [canonical language]]
                             :results)]
    (map (fn [result]
           (json-read-str (.getValue (:structure result))))
         results)))

(defn generate-all [spec language]
