Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns markov.core
- (:require [clojure.contrib.pprint :as pprint])
- (:require [clojure.string :as string]))
- (def fox "the quick brown fox jumps over the lazy dog")
- (defn words [x] (string/split x #"\s"))
- (defn values [y]
- (let [[x & xs] y] {x [xs]}))
- (defn makedb [x]
- (loop [xs (words x) db {}]
- (if (empty? xs)
- db
- (recur (drop 1 xs) (merge-with concat db (values (take 3 xs)))))))
- (defn makedb-from-file [file]
- (makedb (slurp file)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement