Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns markov.core
  2.   (:require [clojure.contrib.pprint :as pprint])
  3.   (:require [clojure.string :as string]))
  4.  
  5. (def fox "the quick brown fox jumps over the lazy dog")
  6.  
  7. (defn words [x] (string/split x #"\s"))
  8.  
  9. (defn values [y]
  10.   (let [[x & xs] y] {x [xs]}))
  11.  
  12. (defn makedb [x]
  13.   (loop [xs (words x) db {}]
  14.     (if (empty? xs)
  15.       db
  16.       (recur (drop 1 xs) (merge-with concat db (values (take 3 xs)))))))
  17. (defn makedb-from-file [file]
  18.   (makedb (slurp file)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement