Skip to content

Instantly share code, notes, and snippets.

@mamonu
Created June 13, 2015 13:38
Show Gist options
  • Select an option

  • Save mamonu/69f4d6188dd5b6a78d7d to your computer and use it in GitHub Desktop.

Select an option

Save mamonu/69f4d6188dd5b6a78d7d to your computer and use it in GitHub Desktop.
markovchain based text obfuscation :)
(defn markov-data [text]
(let [maps
(for [line (clojure.string/split text #"\.")
m (let [l (str line ".")
words
(cons :start (clojure.string/split l #"\s+"))]
(for [p (partition 2 1 (remove #(= "" %) words))]
{(first p) [(second p)]}))]
m)]
(apply merge-with concat maps)))
(defn sentence [data]
(loop [ws (data :start)
acc []]
(let [w (rand-nth ws)
nws (data w)
nacc (concat acc [w])]
(if (= \. (last w))
(clojure.string/join " " nacc)
(recur nws nacc)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment