Skip to content

Instantly share code, notes, and snippets.

@steos
Created December 8, 2012 20:18
Show Gist options
  • Save steos/4241752 to your computer and use it in GitHub Desktop.
Save steos/4241752 to your computer and use it in GitHub Desktop.
minimal "language confluxer"
;; minimal "confluxer"
;; inspired by http://generators.christopherpound.com/
(defn words [text]
(clojure.string/split text #"\s+"))
(defn triplets [s]
(partition 3 1 (clojure.string/capitalize (str s " "))))
(defn conj-triplet [map trip]
(let [[fst snd trd] trip]
(update-in map [(str fst snd)] conj trd)))
(defn follow-map [str]
(reduce conj-triplet {}
(apply concat
(map triplets (words str)))))
(defn gen-word
([fm]
(let [start (rand-nth (filter
#(Character/isUpperCase (first %))
(keys fm)))]
(gen-word fm start start)))
([fm last-pair buffer]
(let [next (rand-nth (fm last-pair))]
(if (= \space next)
(str buffer)
(recur fm
(str (second last-pair) next)
(str buffer next))))))
(comment
(repeatedly 50 (partial gen-word (follow-map (slurp "/home/stefan/jap.txt"))))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment