全裸2012春

おばんです。暑さ寒さも彼岸までと申しますように過ごしやすい季節となりましたが、皆様にはますますご全裸のこととお喜び申し上げます。

遂にpure Ruby形態素解析エンジンがリリースされたという情報を得て、全裸は急げということでさっそく遊ばせていただくことにした次第です。

Rubyによる形態素解析エンジンokura 0.0.1をリリースしました - <s>gnarl,</s>技術メモ”’<marquee><textarea>¥

# coding: utf-8

require 'sinatra'
require 'okura/serializer'
require 'haml'

set :haml, format: :html5
set :dict, File.join(File.dirname(File.expand_path(__FILE__)), "okura_dic")

Tagger = Okura::Serializer::FormatInfo.create_tagger(settings.dict)

get '/' do
  if text = params[:text]
    nodes = Tagger.parse(text)
    @result = nodes.mincost_path.inject("") do |result, node|
      word = node.word
      unless word.left.id == 0
        result << "全裸で" if word.left.text =~ /^動詞/
        result << word.surface
      end
      result
    end
  end

  haml :index
end

__END__

@@index

!!!
%html
  %head
    %meta(charset="utf-8")
    %title zenrize by okura
  %body
    %form(method="get")
      %textarea(name="text" rows="5" cols="40")= params["text"]
      %br
      %input(type="submit")
    %p= @result

ってかんじでやっつけですがHerokuで動くのはカンドーですね!

http://evening-mountain-7832.herokuapp.com/?text=%E3%81%8A%E8%85%B9%E3%81%8C%E7%A9%BA%E3%81%84%E3%81%9F%E6%B0%97%E3%81%8C%E3%81%97%E3%81%BE%E3%81%99

春寒の折り、どうぞ、お身体をおいといください。