                     ((fn [target-spec]
                        (if (= :top target-spec)
                          {}
-                         target-spec)))
-
-                    ;; remove dag_unify-specific metadata:
-                    (dissoc-paths [[:dag_unify.core/serialized]]))
+                         target-spec))))
                 target-json-spec (json/write-str (strip-refs json-input-spec))]
             (log/debug (str "looking for expressions in target language: " target-language
                             " with spec: " target-spec))

                    (log/debug (str "target expression:" (:surface target-structure)))
                    (log/debug (str "target semantics:" (strip-refs target-semantics)))
                    (log/debug (str "source semantics:" (strip-refs source-semantics)))
                    (log/debug (str "json target semantics:" json-target-semantics))
                    (log/debug (str "json source semantics:" json-source-semantics))
                    (let [results
                          (db/exec-raw [(str "SELECT source.surface AS source, source.id AS source_id,
                                             target.surface AS target,target.root AS target_root,
                                             source.structure AS structure,
                                             target.structure::text AS target_structure
                                        FROM (SELECT surface, source.structure->'synsem'->'sem' 
                                                     AS sem,
                                                     source.structure AS structure, source.id
                                                FROM expression AS source
                                               WHERE source.language=?
                                                 AND source.active=true
                                                 AND source.structure->'synsem'->'sem' @> '"
                                             json-source-semantics "' LIMIT 1) AS source
                                  INNER JOIN (SELECT 
                                            DISTINCT surface, target.structure->'synsem'->'sem' AS sem,
                                                     root,structure
                                                FROM expression_with_root AS target
                                               WHERE target.language=?
                                                 AND target.active=true
                                                 AND target.structure->'synsem'->'sem' = '" json-target-semantics "') AS target 
                                          ON (source.surface IS NOT NULL) 
                                         AND (target.surface IS NOT NULL)")
                                        [source-language target-language]]
                                       :results)]
                      (if (nil? (first (map :source results)))
                        ;; TODO: use real sql (from above) rather than this fake string:
                        (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

                      debug (log/debug (str "number of target results:" size-of-results))
                      debug (log/debug (str "index of target result:" index-of-result))
                      target-expression (nth results index-of-result)
                      debug (log/debug (str "target-expression is nil? " (nil? target-expression)))
                      debug (log/trace (str "target-expression is: " target-expression))
                      ]
            
