Minor testing

main
Eric Ihli 4 years ago
parent 186583ffb9
commit 6d4eba92aa

@ -1,5 +1,6 @@
(ns com.owoga.prhyme.gen (ns com.owoga.prhyme.gen
(:require [clojure.string :as string] (:require [clojure.string :as string]
[com.owoga.prhyme.util :as util]
[com.owoga.prhyme.util.weighted-rand :as weighted-rand] [com.owoga.prhyme.util.weighted-rand :as weighted-rand]
[com.owoga.prhyme.util.nlp :as nlp] [com.owoga.prhyme.util.nlp :as nlp]
[com.owoga.prhyme.frp :as frp] [com.owoga.prhyme.frp :as frp]
@ -45,9 +46,9 @@
(let [word (first (filter (fn [word] (let [word (first (filter (fn [word]
(= phrase-word (:norm-word word))) (= phrase-word (:norm-word word)))
words))] words))]
(when (nil? word) (if (nil? word)
(throw (ex-info "Word not found in dictionary." {:word phrase-word}))) (frp/make-word (cons phrase-word (util/get-phones phrase-word)))
word))) word))))
(merge-phrase-words phrase))) (merge-phrase-words phrase)))
(defn adjust-for-markov (defn adjust-for-markov
@ -79,7 +80,7 @@
result]))))) result])))))
(defn adjust-for-rimes (defn adjust-for-rimes
[target-rime dictionary percent] [dictionary percent]
(fn [[words target result]] (fn [[words target result]]
(let [words-with-rime-count (let [words-with-rime-count
(map (map
@ -151,18 +152,26 @@
(apply + (map :syllable-count result))) (apply + (map :syllable-count result)))
(< 5 (count result))))))) (< 5 (count result)))))))
(defn gen-prhymes [words markov poem-lines] (defn gen-prhymes [words adjust poem-lines]
(let [words (map #(assoc % :weight 1) words) (let [words (map #(assoc % :weight 1) words)
words-map (into {} (map #(vector (:norm-word %) %) words))] words-map (into {} (map #(vector (:norm-word %) %) words))]
(map (fn [line] (map (fn [line]
(let [target (frp/phrase->word words line) (let [target (phrase->word words line)
stop (sentence-stop target) stop (sentence-stop target)
weights-adjuster (comp (adjust-for-markov markov 0.9) r (prhymer words adjust target stop)]
(adjust-for-rimes target words-map 0.9))
r (prhymer words weights-adjuster target stop)]
(string/join " " (map #(:norm-word %) (first r))))) (string/join " " (map #(:norm-word %) (first r)))))
poem-lines))) poem-lines)))
(defn phrase-syllable-count [phrase]
(->> phrase
(#(string/split % #" "))
(map (partial phrase->word frp/words))
(map :syllable-count)
(apply +)))
(defn filter-for-syllable-count [syllable-count coll]
(filter #(= syllable-count (phrase-syllable-count %)) coll))
(comment (comment
(take 3 frp/words) (take 3 frp/words)
(phrase->word frp/popular "well-off") (phrase->word frp/popular "well-off")
@ -170,16 +179,17 @@
["mister sandman" ["mister sandman"
"give me dream" "give me dream"
"make him the cutest" "make him the cutest"
"that have ever seen"]) "that i've ever seen"])
(defonce lovecraft-markov (read-string (slurp "lovecraft.edn"))) (defonce lovecraft-markov (read-string (slurp "lovecraft.edn")))
(def adj (comp (adjust-for-markov lovecraft-markov 0.99))) (def adj (comp (adjust-for-markov lovecraft-markov 0.9)
(gen-prhymes frp/popular (adjust-for-rimes words-map 0.9)))
lovecraft-markov (repeatedly 10 #(gen-prhymes frp/popular
["mister sandman" adj
"give me the dream" ["i'm testing rhyme software"
"make him the cutest" "what do you think"]))
"that eye have ever seen"])
(repeatedly 20 #(gen-prhymes frp/popular lovecraft-markov ["mister sandman"])) (take 5 (filter #(= 7 (phrase-syllable-count (first %)))
(repeatedly #(gen-prhymes frp/popular adj ["taylor is my beautiful"]))))
(let [target (frp/phrase->word frp/words "i solemnly swear i am up to no good") (let [target (frp/phrase->word frp/words "i solemnly swear i am up to no good")
words (map #(assoc % :weight 1) frp/popular) words (map #(assoc % :weight 1) frp/popular)

@ -48,13 +48,11 @@
"ah" "ah"
phoneme)) phoneme))
(defn get-phones [dictionary phrase] (defn get-phones [word]
(if (dictionary phrase) (->> (map str (.getPhones cmu-lexicon word nil))
(:phonemes (dictionary phrase)) (map remove-stress)
(->> (map str (.getPhones cmu-lexicon phrase nil)) (map convert-to-sphinx)
(map remove-stress) (map string/upper-case)))
(map convert-to-sphinx)
(map string/upper-case))))
(def phonemap (def phonemap
(->> (io/reader (io/resource "cmudict-0.7b.phones")) (->> (io/reader (io/resource "cmudict-0.7b.phones"))

Loading…
Cancel
Save