On Sep 2, 7:02 pm, tmountain <tinymount...@gmail.com> wrote:
> (defn generate-chain [source]
> (loop [the-list (map #(list (first (split-at 2 %)) (last %))
> (partition 3 1 (.split (.replace source "\n" "
> ") " ")))
> res (hash-map)]
> (if (empty? the-list)
> res
> (recur (filter #(not= (first (first the-list))
> (first %)) the-list)
> (assoc res (first (first the-list))
> (map #(last %)
> (filter #(= (first (first the-list))
> (first %)) the-list)))))))
>
> (println (generate-chain (slurp "big-file.txt")))
I having a bit of a hard time decoding what this function does. I get
that it is producing a Markov chain from a description in a file. Can
you describe the format of the file, and how you are representing the
output (i.e. the chain - is it a map representing the state-transition
matrix)? An example input/output would be fine.
However, I suspect you can solve this by using lazy-seq and perhaps
preprocessing "the-list" into a more efficient data structure.
/Karl
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---