Add lyric suggestion code

main
Eric Ihli 4 years ago
parent 5d67dcc287
commit 874f7df315

@ -309,6 +309,7 @@
["IH2" "N" "V" "IH2" "Z" "AH0" "B" "IH1" "L" "AH0" "T" "IY0"]))
)
(comment
(markov/rhymes models/rhyme-trie-unstressed-trailing-consonants (phonetics/get-phones "food"))
(rhymes "food")
@ -317,3 +318,24 @@
(rhymes-with-frequencies "technology" models/markov-trie models/database)
)
(defn lyric-suggestions [seed-phrase trie database]
(let [realize-seed (fn [seed]
(string/join " " (-> (map database (reverse seed))
butlast
rest)))]
(loop [seed (vec (reverse (map #(get database % 0) (string/split seed-phrase #" "))))]
(cond
(< 20 (count seed)) (realize-seed seed)
(= (database prhyme/BOS) (peek seed)) (realize-seed seed)
:else (recur (conj seed (markov/get-next-markov
trie
seed
(partial remove (fn [child]
(= (.key child) (database prhyme/EOS)))))))))))
(comment
(lyric-suggestions "bother me </s>" models/markov-trie models/database)
)

@ -264,6 +264,25 @@
:opts {}}
(views/wgu request))}))
(defn lyric-suggestions [db cache]
(fn [request]
(let [suggestions
(repeatedly
5
#(linguistics/lyric-suggestions
(-> request :params :rhyme-target)
models/markov-trie
models/database))]
{:status 201
:headers {"Content-Type" "text/html; charset=utf-8"}
:body (views/wrap-with-js
{:db db
:request request
:opts {}}
(views/lyric-suggestions
request
suggestions))})))
(defn show-rhyme-suggestion [db cache]
(fn [request]
(let [suggestions (linguistics/rhymes-with-frequencies-and-rhyme-quality

@ -37,7 +37,7 @@
["/wgu"
{:name ::wgu
:get {:handler (handlers/wgu db cache)}
:post {:handler (handlers/show-rhyme-suggestion db cache)}}]
:post {:handler (handlers/lyric-suggestions db cache)}}]
["/.well-known/*" (ring/create-file-handler
{:root "resources/public/.well-known"})]]]
(timbre/info "Starting router.")

@ -298,6 +298,13 @@
[:iframe {:src "/assets/README_WGU.htm"
:style "background-color: white; width: 100%; height: 760px;"}]])
(defn lyric-suggestions
[request suggestions]
[:div
(wgu request)
(for [suggestion suggestions]
[:div suggestion])])
(defn show-rhyme-suggestion
[request suggestions]
[:div

@ -5,7 +5,8 @@
"src/test"]
:dependencies
[[metasoarous/oz "1.6.0-alpha34"]]
[[metasoarous/oz "1.6.0-alpha34"]
[cljs-ajax/cljs-ajax "0.8.3"]]
:builds
{:frontend

Loading…
Cancel
Save