Include rhyme in best-of calc

main
Eric Ihli 3 years ago
parent 9d0f411012
commit c77e101515

@ -1032,47 +1032,51 @@
banned-words banned-words
(into #{} (->> existing-lines (into #{} (->> existing-lines
(map (comp last last)))) (map (comp last last))))
seed (if existing-lines
(->> existing-lines line
rand-nth (take-until
reverse (best-of-20)
(map first) (fn []
(apply concat) (let [seed (if existing-lines
(#(rhymes (->> existing-lines
rhyme-trie rand-nth
% reverse
(fn [choices] (map first)
(->> choices (apply concat)
(map (fn [[phones wordset]] (#(rhymes
[phones rhyme-trie
(set/difference %
wordset (fn [choices]
banned-words)])) (->> choices
(remove (comp empty? second)))))) (map (fn [[phones wordset]]
rand-nth [phones
((fn [[phones wordset]] (set/difference
(let [word (rand-nth (vec wordset))] wordset
[(rand-nth (phonetics/get-phones word)) banned-words)]))
word]))) (remove (comp empty? second))))))
vector) rand-nth
(->> (get-next-markov ((fn [[phones wordset]]
markov-trie (let [word (rand-nth (vec wordset))]
[eos eos eos] [(rand-nth (phonetics/get-phones word))
(fn [children] word])))
(remove vector)
#(#{eos bos} (.key %)) children))) (->> (get-next-markov
database markov-trie
(#(vector (rand-nth (phonetics/get-phones %)) %)) [eos eos eos]
vector)) (fn [children]
line (take-until (remove
(best-of-20) #(#{eos bos} (.key %)) children)))
#(tightly-generate-n-syllable-sentence-v2 database
database (#(vector (rand-nth (phonetics/get-phones %)) %))
markov-trie vector))
4 line (tightly-generate-n-syllable-sentence-v2
syllable-count database
(make-markov-filter [eos bos]) markov-trie
seed))] 4
syllable-count
(make-markov-filter [eos bos])
seed)]
line)))]
(recur (rest scheme) (recur (rest scheme)
(update result (first scheme) (fnil conj []) line))))))) (update result (first scheme) (fnil conj []) line)))))))
@ -1081,6 +1085,19 @@
(rhyme-from-scheme-v2 (rhyme-from-scheme-v2
scheme database markov-tight-trie rhymetrie)) scheme database markov-tight-trie rhymetrie))
(phonetics/get-phones "unleashed")
(rhymes
rhymetrie
["IY" "SH" "T"]
(fn [choices]
(->> choices
(map (fn [[phones wordset]]
[phones
(set/difference
wordset
#{"unleashed"})]))
(remove (comp empty? second)))))
) )
(comment (comment

@ -167,6 +167,12 @@
(#(parse-top-n % 100))) (#(parse-top-n % 100)))
) )
(comment
(likely-sentence?
"have s y como tu cama")
)
(defn valid-sentence? (defn valid-sentence?
"Tokenizes and parses the phrase using OpenNLP models from "Tokenizes and parses the phrase using OpenNLP models from
http://opennlp.sourceforge.net/models-1.5/ http://opennlp.sourceforge.net/models-1.5/

Loading…
Cancel
Save