                                                WHERE source.language=?
                                                  AND source.active=true
                                                  AND source.structure->'synsem'->'sem' @> '"
-                                             json-source-semantics "' LIMIT 1) AS source
+                                                                        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

                                                           ON (source.surface IS NOT NULL) 
                                                          AND (target.surface IS NOT NULL)
                                                          AND (true)")
                                        [source-language target-language]]
                                       :results)]
                      (if (nil? (first (map :source results)))
                        (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 (strip-refs (deserialize
                                                               (read-string (:target target-expression))))
                                                   [:synsem :sem])
                                           "; used source semantics:" source-semantics "; SQL:" sql)]
                          (log/error message)
                          (throw (Exception. message))))
                        (let [debug (log/trace (str "source-structure:"
                                                    (first (map :structure results))))
                              debug (log/trace (str "read from target_structure:"
                                                    (first (map :target_structure results))))
                              debug (log/trace (str "target structures: (via read-str)" 
                                                    (read-str (first (map :target_structure results)))))
                              debug (log/trace (str "target-structures (via json-read-str):" 
                                                    (json-read-str (first (map :target_structure results)))))]
                          {:source-id (first (map :source_id results))
                           :source (first (map :source results))
                           :target-spec target-spec
                           :targets (map :target results)})))))))))))
    
(defn get-lexeme [canonical language & [ spec ]]
  "get a lexeme from the database given the canonical form, given a

                  ;; set to true or false, while subjects in English, at present, lack this
                  ;; (though this key might be added to the English lexicon later at
                  ;;  some point).
                  (let [sanity (log/error (str "type of target-expression:" (type target-expression)))]
                    (let [result (deserialize (read-string (:target target-expression)))]
                        ;; TODO: allow queries that have refs - might be
                        ;; useful for modeling anaphora and binding.
                      (let [target-semantics (get-in result [:synsem :sem])]
                        (let [source-language-keyword (keyword source-language)]
                          (let [target-language-keyword (keyword target-language)]
                            (let [semantic-correspondence
                                  (if (or true (nil? @((:en models source-language-keyword))))
                                    (do
                                      (log/error (str "type of models:" (type models)))
                                      (log/error (str "type of italian model:" (type (get models :it))))
                                      (log/error (str "well it's too bad that dereferencing the model won't work. instead we'll used a hard-wired semantic-correspondence."))
                                      [[:obj :null]
                                       [:obj :number]
                                       [:shared-with-obj]
                                       [:subj :null]
                                       [:subj :number]])
                                    (do
                                      (log/error (str "wow, for some reason the model is non-null as I would hope."))
                                      (-> @((models source-language-keyword))
                                          :semantic-correspondence
                                          target-language-keyword)))]
                              (let [source-semantics (-> result
                                                         (get-in [:synsem :sem])
                                                         (dissoc-paths semantic-correspondence)
                                                         strip-refs)]
                                (let [json-target-semantics (json/write-str (strip-refs (get-in result [:synsem :sem])))]
                                  (let [json-source-semantics (json/write-str (strip-refs source-semantics))]
                                    (log/debug (str "target expression:" (:surface result)))
                                    (log/debug (str "target semantics:" (strip-refs (get-in result [:synsem :sem]))))
                                    (log/debug (str "source semantics:" (strip-refs source-semantics)))
                                    (log/debug (str "json target semantics:" json-target-semantics))
                                    (log/debug (str "json source:" 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
