     [clojure.data.json :as json]
     [clojure.string :as string]
     [clojure.tools.logging :as log]
-    [dag-unify.core :refer [get-in strip-refs serialize unify ref?]]
+    [dag-unify.core :refer [get-in merge strip-refs serialize unify ref?]]
     [babel.engine :as engine]
     [babel.korma :as korma]
     [korma.core :refer [exec-raw]]))

        target-language-sentence (engine/generate spec target-language-model :enrich true)
        
        target-language-sentence (if (:morph-walk-tree target-language-model)
                                   (do
                                     ((:morph-walk-tree target-language-model) target-language-sentence)
                                     target-language-sentence)
                                   (do (log/warn (str "there is no morph-walk-tree function for the model:"
                                                      (:name target-language-model) " of language: "
                                                      (:language target-language-model)))

                      ;; an entire sentence.
                                             
                      (throw (Exception. message))))))

        ;; TODO: add warning if semantics of target-expression is merely :top - it's
        ;; probably not what the caller expected. Rather it should be something more
        ;; specific, like {:pred :eat :subj {:pred :antonio}} ..etc.
        source-language-sentence (engine/generate {:synsem {:sem semantics}}
                                                  source-language-model :enrich true)

        source-language-sentence (if (:morph-walk-tree source-language-model)
                                   (merge ((:morph-walk-tree source-language-model) source-language-sentence)
                                          source-language-sentence)
                                   (do (log/warn (str "there is no morph-walk-tree function for the model:"
                                                      (:name source-language-model) " of language: "
                                                      (:language source-language-model)))
                                       source-language-sentence))

        source-fo (:morph source-language-model)
        source-language-surface (source-fo source-language-sentence)
        debug (log/debug (str "source surface: " source-language-surface))

        error (if (or (nil? source-language-surface)
                      (= source-language-surface ""))
                (let [message (str "Could not generate a sentence in source language '" source-language 
                                   "' for this semantics: " semantics "; target language was: " (:language target-language-model)
                                   "; target expression was: '" ((:morph  @target-language-model) target-language-sentence) "'"
                                   "; target rule was: '" (:rule target-language-sentence) "'"
                                   "; target head rule was: '" (:rule (:head target-language-sentence)) "'"
