|
|
@ -1,6 +1,9 @@
|
|
|
|
(ns examples.scratch
|
|
|
|
(ns examples.scratch
|
|
|
|
(:require [clojure.java.io :as io]
|
|
|
|
(:require [clojure.java.io :as io]
|
|
|
|
[clojure.string :as string]
|
|
|
|
[clojure.string :as string]
|
|
|
|
|
|
|
|
[taoensso.nippy :as nippy]
|
|
|
|
|
|
|
|
[com.owoga.tightly-packed-trie :as tpt]
|
|
|
|
|
|
|
|
[com.owoga.trie :as trie]
|
|
|
|
[com.owoga.phonetics :as phonetics]
|
|
|
|
[com.owoga.phonetics :as phonetics]
|
|
|
|
[com.owoga.corpus.markov :as markov]
|
|
|
|
[com.owoga.corpus.markov :as markov]
|
|
|
|
[clojure.set]
|
|
|
|
[clojure.set]
|
|
|
@ -837,10 +840,22 @@
|
|
|
|
(defn good-turing-discount [trie c]
|
|
|
|
(defn good-turing-discount [trie c]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(def database (nippy/thaw-from-file "/home/eihli/.models/markov-database-4-gram-backwards.bin"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(def markov-tight-trie
|
|
|
|
|
|
|
|
(tpt/load-tightly-packed-trie-from-file
|
|
|
|
|
|
|
|
"/home/eihli/.models/markov-tightly-packed-trie-4-gram-backwards.bin"
|
|
|
|
|
|
|
|
(markov/decode-fn database)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(def rhyme-trie
|
|
|
|
|
|
|
|
(into
|
|
|
|
|
|
|
|
(trie/make-trie)
|
|
|
|
|
|
|
|
(nippy/thaw-from-file
|
|
|
|
|
|
|
|
"/home/eihli/.models/rhyme-trie-unstressed-vowels-and-trailing-consonants.bin")))
|
|
|
|
|
|
|
|
|
|
|
|
(def rhymetrie
|
|
|
|
(def rhymetrie
|
|
|
|
(markov/->RhymeTrie
|
|
|
|
(markov/->RhymeTrie
|
|
|
|
markov/rhyme-trie
|
|
|
|
rhyme-trie
|
|
|
|
(fn [phones]
|
|
|
|
(fn [phones]
|
|
|
|
(->> phones
|
|
|
|
(->> phones
|
|
|
|
prhyme/take-vowels-and-tail-consonants
|
|
|
|
prhyme/take-vowels-and-tail-consonants
|
|
|
@ -851,12 +866,39 @@
|
|
|
|
(comment
|
|
|
|
(comment
|
|
|
|
(->> (prhyme/phrase->all-phones "technology")
|
|
|
|
(->> (prhyme/phrase->all-phones "technology")
|
|
|
|
(map first)
|
|
|
|
(map first)
|
|
|
|
(mapcat (partial markov/rhymes markov/rhymetrie))
|
|
|
|
(map (fn [phones]
|
|
|
|
|
|
|
|
[phones (->> (markov/rhymes rhymetrie phones)
|
|
|
|
(map second)
|
|
|
|
(map second)
|
|
|
|
(reduce into #{}))
|
|
|
|
(reduce into #{}))]))
|
|
|
|
|
|
|
|
(map (fn [[phones1 words]]
|
|
|
|
(markov/get-next-markov
|
|
|
|
[phones1 (->> (mapcat prhyme/phrase->all-phones words)
|
|
|
|
markov/markov-tight-trie
|
|
|
|
(map (fn [[phones2 word]]
|
|
|
|
[1 1])
|
|
|
|
[phones2 word (prhyme/quality-of-rhyme-phones phones1 phones2)])))]))
|
|
|
|
|
|
|
|
(map (fn [[phones1 words]]
|
|
|
|
|
|
|
|
[phones1 (sort-by (fn [[_ _ quality]]
|
|
|
|
|
|
|
|
(- quality))
|
|
|
|
|
|
|
|
words)]))
|
|
|
|
|
|
|
|
#_(reduce into #{}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(database "technology")
|
|
|
|
|
|
|
|
(loop [seed [1]]
|
|
|
|
|
|
|
|
(let [options (repeatedly
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
#(markov/get-next-markov
|
|
|
|
|
|
|
|
markov-tight-trie
|
|
|
|
|
|
|
|
seed
|
|
|
|
|
|
|
|
(fn [children]
|
|
|
|
|
|
|
|
(remove
|
|
|
|
|
|
|
|
(fn [child]
|
|
|
|
|
|
|
|
(let [lookup (.key child)
|
|
|
|
|
|
|
|
[word freq] (get child [])]
|
|
|
|
|
|
|
|
(#{(database prhyme/EOS) (database prhyme/BOS)} word)))
|
|
|
|
|
|
|
|
children))))]
|
|
|
|
|
|
|
|
(println (map vector options (map database options)))
|
|
|
|
|
|
|
|
(let [choice (Integer/parseInt (read-line))]
|
|
|
|
|
|
|
|
(if (= choice 0)
|
|
|
|
|
|
|
|
(map database (reverse seed))
|
|
|
|
|
|
|
|
(recur (conj seed choice))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(map database [1 1 5133 1296 68 636 12 10])
|
|
|
|
)
|
|
|
|
)
|
|
|
|