diff --git a/web/src/com/darklimericks/linguistics/core.clj b/web/src/com/darklimericks/linguistics/core.clj index b1d9df1..ba03e68 100644 --- a/web/src/com/darklimericks/linguistics/core.clj +++ b/web/src/com/darklimericks/linguistics/core.clj @@ -350,14 +350,12 @@ (reduce (fn convert-to-hashmap [acc [pronunciation rhyming-words]] (reduce (fn [acc [phones word rhyme-quality]] - (assoc-in acc [pronunciation phones] {:word word :rhyme-quality rhyme-quality})) + (assoc-in acc [pronunciation phones] {:word word + :rhyme-quality rhyme-quality + :pronunciation phones})) acc rhyming-words)) - {}) - #_#_#_#_(mapcat second) - (sort-by #(- (nth % 2))) - (take 20) - (map second))) + {}))) (comment (rhymes-by-quality "boss hog") diff --git a/web/src/com/darklimericks/server/handlers.clj b/web/src/com/darklimericks/server/handlers.clj index 1565f22..7cf9344 100644 --- a/web/src/com/darklimericks/server/handlers.clj +++ b/web/src/com/darklimericks/server/handlers.clj @@ -313,3 +313,6 @@ (views/rhymes-with-quality-and-frequency request (linguistics/rhymes-with-quality-and-frequency target)))}))) + +(comment + (linguistics/rhymes-with-quality-and-frequency "poverty")) diff --git a/web/src/com/darklimericks/server/router.clj b/web/src/com/darklimericks/server/router.clj index 003ea66..d306ac2 100644 --- a/web/src/com/darklimericks/server/router.clj +++ b/web/src/com/darklimericks/server/router.clj @@ -41,7 +41,7 @@ :post {:handler (handlers/lyric-suggestions db cache)}}] ["/rhyme" {:name ::rhyme - :get {:handler (handlers/lyric-suggestions db cache)}}]] + :get {:handler (handlers/rhymes-with-quality-and-frequency db cache)}}]] ["/.well-known/*" (ring/create-file-handler {:root "resources/public/.well-known"})]]] (timbre/info "Starting router.") diff --git a/web/src/com/darklimericks/server/views.clj b/web/src/com/darklimericks/server/views.clj index 1f7b9c0..56518ca 100644 --- a/web/src/com/darklimericks/server/views.clj +++ b/web/src/com/darklimericks/server/views.clj @@ -4,7 +4,8 @@ [clojure.string :as string] [com.darklimericks.db.albums :as db.albums] [com.darklimericks.db.artists :as db.artists] - [com.darklimericks.server.util :as util])) + [com.darklimericks.server.util :as util] + [com.darklimericks.server.models :as models])) (defn wrapper ([db request opts & body] @@ -283,9 +284,9 @@ [:div [:h2 "Generate Rhyme"] (form/form-to - [:post (util/route-name->path - request - :com.darklimericks.server.router/wgu)] + [:get (util/route-name->path + request + :com.darklimericks.server.router/rhyme)] (form/label "rhyme-target" "Target word or phrase for which to find rhyme suggestions") @@ -350,4 +351,30 @@ [:div (string/join " - " [suggestion freq p1 p2])])})]) (defn rhymes-with-quality-and-frequency - []) + [request suggestions] + (let [rhymes (->> (for [[pronunciation rhymes] suggestions] + (for [[phones rhyme] rhymes] + rhyme)) + flatten + distinct) + grouped-by-quality (group-by :rhyme-quality rhymes) + top-20-by-quality (reduce + (fn [acc [_ rhymes]] + (into acc (take 20 (sort-by + (comp - :freq) + rhymes)))) + [] + grouped-by-quality) + top-20-rhyme (take 60 (sort-by + (juxt (comp - :rhyme-quality) + (comp - :freq)) + top-20-by-quality))] + [:div + (wgu + request + {:rhymes + [:div + [:table {:style "margin: auto;"} + [:tr [:th "Rhyme"] [:th "Pronunciation"] [:th "Quality"] [:th "Frequency"]] + (for [{:keys [word pronunciation rhyme-quality freq]} top-20-rhyme] + [:tr [:td word] [:td (String/join "-" pronunciation)] [:td rhyme-quality] [:td freq]])]]})]))