Last active
August 29, 2015 13:56
-
-
Save kawasima/9182792 to your computer and use it in GitHub Desktop.
適当な氏名を自動生成する。
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
(require '[clojure.string :as string] | |
'[clojure.java.io :as io]) | |
(defn extract-name [name-seq] | |
(let [sei (atom []) | |
mei (atom [])] | |
(doseq [x name-seq] | |
(let [kana (first x)] | |
(doseq [p (rest x)] | |
(let [[n t] (string/split p #";")] | |
(case t | |
"姓" (swap! sei conj [n kana]) | |
"名" (swap! mei conj [n kana]) | |
nil))))) | |
(repeatedly (fn [] [(rand-nth @sei) (rand-nth @mei)])))) | |
(defn generate-random-name [n] | |
(with-open [rdr (io/reader "http://openlab.jp/skk/skk/dic/SKK-JISYO.jinmei" :encoding "euc-jp")] | |
(->> (line-seq rdr) | |
(remove #(.startsWith % ";")) | |
(map #(string/split % #"\s*/\s*")) | |
(extract-name) | |
(take n)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment