module HatenaKeywordHaiku
Public Class Methods
generate(*args)
click to toggle source
# File lib/plugins/hatena_keyword_haiku.rb, line 27 def self.generate(*args) args = [5,7,5] if args.empty? args.map{ |len| words[len.to_i].choice rescue raise "No word which length is #{len}" }.map{ |w| w.word }.join(' ') end
setup(csv_path = '/tmp/keywordlist_furigana.csv', csv_url = 'http://d.hatena.ne.jp/images/keyword/keywordlist_furigana.csv')
click to toggle source
d.hatena.ne.jp/hatenadiary/20060922/1158908401
# File lib/plugins/hatena_keyword_haiku.rb, line 36 def self.setup(csv_path = '/tmp/keywordlist_furigana.csv', csv_url = 'http://d.hatena.ne.jp/images/keyword/keywordlist_furigana.csv') return if @@words @@words = { } csv_path = File.expand_path(csv_path) unless File.exists? csv_path puts "haiku: downloading CSV" open(csv_path, 'w'){ |f| f.write(open(csv_url).read) } end puts "haiku: parsing CSV" open(csv_path).each_line{ |line| yomi, word = *NKF.nkf('-w', line.chomp).split(/\t/) next unless yomi and word w = Word.new(word, yomi) @@words[w.length] = [] unless @@words.has_key? w.length @@words[w.length].push w } puts "haiku: setup done" @@words end
words()
click to toggle source
# File lib/plugins/hatena_keyword_haiku.rb, line 60 def self.words setup unless @@words @@words end