Update to use prhyme scheme gen

main
Eric Ihli 3 years ago
parent 82a4d95c16
commit 23c0dc8de8

@ -95,20 +95,31 @@
(-> state/system :database.kv/connection) (-> state/system :database.kv/connection)
(car-mq/enqueue "limericks" '((A 8) (A 8) (B 4) (B 4) (A 8)))))) (car-mq/enqueue "limericks" '((A 8) (A 8) (B 4) (B 4) (A 8))))))
(car/wcar (->> (car/wcar
(-> state/system :database.kv/connection) (-> state/system :database.kv/connection)
(car/ping) #_#_(car/ping)
(car/set "baz" "buzz") (car/set "baz" "buzz")
(car/get "baz")) (car/keys "*"))
(map
#(car/wcar (-> state/system :database.kv/connection) (car/get %))))
(car/wcar
(-> state/system :database.kv/connection)
(car/get "carmine:session:174a7525-04cb-4d73-a03c-1141bef6ad75"))
(limericks/get-artist-and-album-for-new-limerick (-> state/system :database.sql/connection)) (limericks/get-artist-and-album-for-new-limerick (-> state/system :database.sql/connection))
(repeatedly (repeatedly
1 1
(fn [] (fn []
(let [handler (handlers/limerick-generation-post-handler (let [handler (handlers/limerick-generation-post-handler
(-> state/system :database.sql/connection) (-> state/system :com.darklimericks.db.core/connection)
(-> state/system :app/cache))] (-> state/system :com.darklimericks.kv.core/connection))
(handler {:params {:scheme "A9 A9 B5 B5 A9" #_'((A 9) (A 9) (B 5) (B 5) (A 9))}})))) session-id "carmine:session:174a7525-04cb-4d73-a03c-1141bef6ad75"
router (state/system :com.darklimericks.server.router/router)]
(handler {:params {:scheme "A9 A9 B6 B6 A9" #_'((A 9) (A 9) (B 5) (B 5) (A 9))}
:session/key session-id
::reitit/router router}))))
;; If the namespace gets dirty, this can clear it up. ;; If the namespace gets dirty, this can clear it up.
(run! (run!

@ -14,3 +14,8 @@
(map string/capitalize) (map string/capitalize)
(string/join " "))) (string/join " ")))
(defn rhymes
"All rhymes. Slightly flexible. Ordered by number of rhyming syllables.
Most generic and likely desired rhyming algorithm."
[target])

@ -2,13 +2,20 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[reitit.core :as reitit] [reitit.core :as reitit]
[com.darklimericks.db.artists :as artists] [com.darklimericks.db.artists :as artists]
[com.owoga.prhyme.data-transform :as data-transform]
[com.darklimericks.db.albums :as albums] [com.darklimericks.db.albums :as albums]
[com.darklimericks.db.limericks :as db.limericks] [com.darklimericks.db.limericks :as db.limericks]
[com.darklimericks.util.identicon :as identicon] [com.darklimericks.util.identicon :as identicon]
[com.darklimericks.linguistics.core :as linguistics] [com.darklimericks.linguistics.core :as linguistics]
[com.owoga.prhyme.limerick :as limerick] [com.owoga.corpus.markov :as markov]
[com.owoga.prhyme.data.dictionary :as dict] [com.owoga.prhyme.data.dictionary :as dict]
[com.owoga.prhyme.data.darklyrics :refer [darklyrics-markov-2]])) [com.owoga.prhyme.data.darklyrics :refer [darklyrics-markov-2]]
[com.owoga.tightly-packed-trie :as tpt]
[clojure.java.io :as io]
[com.owoga.tightly-packed-trie.encoding :as encoding]
[taoensso.nippy :as nippy]
[com.owoga.trie :as trie]
[taoensso.timbre :as timbre]))
(defn parse-scheme-element [[tokens ctx]] (defn parse-scheme-element [[tokens ctx]]
(cond (cond
@ -99,12 +106,36 @@
(map string/capitalize) (map string/capitalize)
(string/join " "))) (string/join " ")))
(def database (nippy/thaw-from-file (io/resource "models/database.bin")))
(def rhyme-trie (into (trie/make-trie) (nippy/thaw-from-file (io/resource "models/rhyme-trie.bin"))))
(def markov-trie (tpt/load-tightly-packed-trie-from-file
(io/resource "models/tpt.bin")
(markov/decode-fn database)))
(comment
(->> (markov/rhyme-from-scheme
'[[A 9] [A 9] [B 6] [B 6] [A 9]]
database
markov-trie
rhyme-trie)
(map reverse)
(map (partial map second))
(map data-transform/untokenize))
)
(defn generate-limerick-worker [db message] (defn generate-limerick-worker [db message]
(timbre/info "Begin generate limerick worker.")
(let [{:keys [scheme session-id]} message (let [{:keys [scheme session-id]} message
limerick (limerick/rhyme-from-scheme limerick (->> (markov/rhyme-from-scheme
dict/prhyme-dict scheme
darklyrics-markov-2 database
scheme) markov-trie
rhyme-trie)
(map reverse)
(map (partial map second))
(map data-transform/untokenize))
_ (timbre/info "Limerick: " limerick)
album-artist (get-artist-and-album-for-new-limerick db) album-artist (get-artist-and-album-for-new-limerick db)
[artist-id album-id] album-artist [artist-id album-id] album-artist
album (albums/album db album-id)] album (albums/album db album-id)]

Loading…
Cancel
Save