Created
June 13, 2015 13:38
-
-
Save mamonu/69f4d6188dd5b6a78d7d to your computer and use it in GitHub Desktop.
markovchain based text obfuscation :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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