Last active
August 29, 2015 14:25
-
-
Save schaueho/79c8d19a7304a2994599 to your computer and use it in GitHub Desktop.
Generate a random text collection
This file contains 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 file2wordlist [wordlistfile] | |
(-> (slurp wordlistfile) | |
(str/triml) | |
(str/split #"\s+") | |
((partial concat ["." ","])))) | |
(defn generate-random-text-coll | |
"Generate a random text collection with nrtexts texts that are up to maxlength long. | |
Wordlist should be a file with one word per line." | |
[wordlist nrtexts maxlength] | |
(let [words (file2wordlist wordlist) | |
lengths (range 1 maxlength)] ; we don't want 0 length texts | |
(repeatedly nrtexts | |
#(repeatedly (rand-nth lengths) | |
(fn [] | |
(rand-nth words)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment