Working rhyme from scheme

But markov doesn't look like it's working. Sentences don't make sense.
main
Eric Ihli 3 years ago
parent 1f7a013dca
commit 1544680f55

@ -183,7 +183,7 @@
(def markov-trie (into (trie/make-trie) (nippy/thaw-from-file "/tmp/trie.bin"))) (def markov-trie (into (trie/make-trie) (nippy/thaw-from-file "/tmp/trie.bin")))
(def database (nippy/thaw-from-file "/tmp/database.bin")) (def database (nippy/thaw-from-file "/tmp/database.bin"))
(def markov-tight-trie (tpt/tightly-packed-trie markov-trie encode-fn (decode-fn db))) (def markov-tight-trie (tpt/tightly-packed-trie markov-trie encode-fn (decode-fn database)))
) )
@ -278,7 +278,8 @@
result []] result []]
(let [choices (words-fn (rhyme-choices trie target-rhyme))] (let [choices (words-fn (rhyme-choices trie target-rhyme))]
(if (or (empty? target-rhyme) (if (or (empty? target-rhyme)
(prhyme/last-primary-stress? (reverse target-rhyme))) (and (not-empty choices)
(prhyme/last-primary-stress? (reverse target-rhyme))))
(into result choices) (into result choices)
(recur (butlast target-rhyme) (recur (butlast target-rhyme)
(into result choices))))))) (into result choices)))))))
@ -537,11 +538,11 @@
rhyme-wordset-fn] rhyme-wordset-fn]
(let [eos (database prhyme/EOS) (let [eos (database prhyme/EOS)
bos (database prhyme/BOS) bos (database prhyme/BOS)
rhyme (->> (rhyme-choices-walking-target-rhyme choices (rhyme-choices-walking-target-rhyme
rhyme-trie rhyme-trie
target-rhyme target-rhyme
rhyme-wordset-fn) rhyme-wordset-fn)
rand-nth)] rhyme (update (rand-nth choices) 1 (comp rand-nth vec))]
(loop [phrase [rhyme]] (loop [phrase [rhyme]]
(if (<= target-sentence-syllable-count (if (<= target-sentence-syllable-count
(prhyme/count-syllables-of-phrase (prhyme/count-syllables-of-phrase
@ -558,7 +559,7 @@
(fn [[lookup [word frequency]]] (fn [[lookup [word frequency]]]
(or (markov-remove-fn [lookup [word frequency]]) (or (markov-remove-fn [lookup [word frequency]])
(#{eos bos} word)))))] (#{eos bos} word)))))]
[(phonetics/get-phones word) word])))))))) [(rand-nth (phonetics/get-phones word)) word]))))))))
;;;; Demo ;;;; Demo
;;;; ;;;;
@ -642,9 +643,24 @@
(map #(update % 0 rand-nth)) (map #(update % 0 rand-nth))
(apply map vector) (apply map vector)
((fn [[phones words]] ((fn [[phones words]]
[(string/join " " (reduce into [] phones)) (string/join " " words)])) [(reduce into [] phones) (string/join " " words)]))
(first))) (first)))
(comment
(let [sentence '[[[[F L OW1]] flow]
[[[AH0 N D] [AE1 N D]] and]
[[[S IY1 K]] seek]
[[[F IH1 NG G ER0 Z]] fingers]
[[[Y AO1 R] [Y UH1 R]] your]
[[[TH R UW1]] through]
[[[S T R EH1 NG K TH] [S T R EH1 NG TH]]
strength]
[[[F AY1 N D]] find]
[[[K AE1 N] [K AH0 N]] can]]]
(sentence->phones sentence))
)
(defn rhyme-from-scheme (defn rhyme-from-scheme
"scheme of format [[A 9] [A 9] [B 5] [B 5] [A 9]] "scheme of format [[A 9] [A 9] [B 5] [B 5] [A 9]]
@ -678,19 +694,21 @@
syllable-count syllable-count
(constantly false) (constantly false)
;; words-fn ;; words-fn
;; ([("G" "AO1" "B") "bog"] [("G" "AO1" "F") "fog"]) ;; ([("G" "AO1" "B") #{"bog"}] [("G" "AO1" "F") #{"fog"}])
(fn [rhyming-words] (fn [rhyming-words]
(->> (map (fn [[phones wordset]] (->> (map (fn [[phones wordset]]
[phones (set/difference [phones (->> (set/difference
wordset wordset
banned-words)]) banned-words))])
rhyming-words) rhyming-words)
(remove (fn [[phones wordset]] (remove (fn [[phones wordset]]
(empty? wordset))))))) (empty? wordset)))))))
rhyme (reverse (sentence->phones line))] rhyme (reverse (sentence->phones line))]
(println line)
(recur (rest scheme) (recur (rest scheme)
(assoc line-phones pattern rhyme) (assoc line-phones pattern rhyme)
(conj result (reverse line))))))) (conj result (reverse line)))))))
(comment (comment
(tightly-generate-n-syllable-sentence (tightly-generate-n-syllable-sentence
database database
@ -704,6 +722,7 @@
markov-tight-trie markov-tight-trie
rhyme-trie) rhyme-trie)
(trie/lookup markov-tight-trie nil)
(tightly-generate-n-syllable-sentence-rhyming-with (tightly-generate-n-syllable-sentence-rhyming-with
database database
markov-trie markov-trie

Loading…
Cancel
Save