ãã¯èªå¤æï¼åé³ãã¯ç¨æè©ãã¼ã¿çæï¼Rubyã¹ã¯ãªãã
å¹´æ«å¹´å§ã¯åé³ãã¯ä¸æ§ã
ãããã触ã£ã¦ã¦æã£ãã®ã¯ãæè©ã®ããã¹ãèµ·ããããã£ããé¢åãããã¨ãããã¨ãã ããã以ä¸ã®ãããªãã¨ãããå¿ è¦ãããã¾ãã
- æ¼¢åã¯ãã¹ã¦ã«ãã«ãã
- å©è©ã®ãã¯ãã¯çºé³ã©ãããããã«ããï¼ä¾ï¼ããã¯ä½âããããªã«ï¼
- ä»ã«ã表è¨ã¨çºé³ãéããã®ã¯çºé³ã©ããã«ããï¼ä¾ï¼ã©ããããããã®âã©ããããããã®ï¼
- ä¿é³ã®ãã£ãã¯ç´åã®æ¯é³ã«ããæ¹ããã¾ãããï¼ä¾ï¼ã¡ãã£ã¨ã§ããã®ã âã¡ããã¨ã§ããã®ã ï¼
ãããªããã§ãããã£ãå¤æãèªåã§ãã£ã¦ãããããã°ã©ã ãä½ã£ã¦ã¿ã¾ãããä¸çªå¤§å¤ãªä¸è¨1ã3ã¯MeCabãå
¥ããã°å
¨é¨ãã£ã¦ãããã®ã§ãå®ã¯ä¿é³ã®å¦çãæ¸ãã ãã§ããこのへんãåèã«ãã¾ããã
ãããã«id:navããã®自動作詞ã§çæããæè©ãå¤æããã¨ä»¥ä¸ã®ããã«ãªãã¾ãã
å®è¡
ruby mikugo.rb < kanji.txt > kana.txt
å
¥å
ãããããããã®ã¾ã¶ã
ã²ããããç§å¯ãã¢ã¬ã«ã®ã¼ãé¡
åã®è¸ã¯ç §ãé ãã®ãæããã¦ãã
å ãèªåãã´ã¼ã¹ãã®ãè½æ¸ãã¨ãä¼è©±
ãã¼ããèæ°æ¥¼ã¯ãå½±ãæã
éæ§çãªã¨ã¯ã¹ã¿ã·ã¼ã®ãçµããã¨ãããªããã
æããã®ãèªç±ã¨å°å³
ã¹ã¿ã¤ã«ã®ã¬ãã¦ããããã®ã¾ã¶ã
ã²ããããç§å¯ãã¢ã¬ã«ã®ã¼ãé¡
åã®è¸ã¯ç §ãé ãã®ãæããã¦ãã
åºå
ããããã¹ãã©ã®ã¾ã¶ã
ã²ãããã²ã¿ã¤ããããããããã¿
ãã¿ã®ãããã¦ããããã®ãªããã¦ãã
ã²ãããã¶ããããã¨ã®ããããã¨ããã
ãã¼ãããããããããããããã
ãããã¦ããªããããããã®ãããã¨ããªããã
ã»ãããã®ãããã¨ã¡ã
ããããã®ã¬ãã¦ã¹ãã©ã®ã¾ã¶ã
ã²ãããã²ã¿ã¤ããããããããã¿
ãã¿ã®ãããã¦ããããã®ãªããã¦ãã
#!/usr/bin/ruby $KCODE='UTF8' require 'jcode' require 'MeCab' class Mikugo def initialize @mecab = MeCab::Tagger.new('-F%pS%f[8] -U%M -E\n') end def generate(s) ss = @mecab.parse(s) # æ¼¢å->ã«ã¿ã«ãå¤æ ss.tr!('ã¢-ã³','ã-ã') # ã«ã¿ã«ã->ã²ãããªå¤æ ss.gsub!(/[ ã]/,'') # 空ç½æåã®åé¤ ss.gsub!('ã','ã') # 'ã'->'ã'å¤æ ss = conv_sokuon_chouon(ss) # ä¿é³ãé·é³ã®å¦ç return ss end def conv_sokuon_chouon(s) a = s.split(/[ã£ã¼]/) a.length.times {|i| if (i > 0) # ä¿é³ãé·é³ã®å ´åã¯1æååã®æ¯é³ã«å¤æ pre_char = a[i-1][/.$/] a[i] = get_vowel(pre_char) + a[i] end } return a.join end # æ¯é³å¤æ def get_vowel(c) if "ãããããªã¯ã¾ãããããã ã°ã±ã".include?(c) return "ã" end if "ãããã¡ã«ã²ã¿ãããã¢ã³ã´".include?(c) return "ã" end if "ãããã¤ã¬ãµãããããã¥ã¶ã·ã ".include?(c) return "ã" end if "ãããã¦ãã¸ããããã§ã¹ãº".include?(c) return "ã" end if "ãããã¨ã®ã»ããããããã©ã¼ã½ã".include?(c) return "ã" end return "ï¼" end end #--------------------------- miku = Mikugo.new() while( s = gets ) puts miku.generate(s) end