6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[ruby]mecabとnattoを使用して形態素解析してみた

Posted at

100文字の文字列をnattoを使用して形態素解析してみました。
形態素解析エンジンにはmecabを使用。
文章を解析して配列に入れるとこまでを1万回繰り返しました。
VM上でやっています。数値は参考程度に。

ruby
equire 'benchmark'
require 'natto'

text = "人は歩みをとめたときに、そして挑戦をあきらめた時に年老いていくのだと思います。この道を行けばどうなるものか、危ぶむなかれ。危ぶめば道はなし。踏み出せばその一足が道となる。迷わず行けよ。行けばわかるさ。"

Benchmark.bm(7) do |x|
  x.report("natto") {
    10000.times do
      arr=Array.new
      nm = Natto::MeCab.new
      nm.parse(text) do |n|
        arr<<n.surface
      end
    end
  }
end
  • 結果
user system total real
natto 10.780000 3.940000 14.720000 14.749078

ちなみに
arrの値は
["人", "は", "歩み", "を", "とめ", "た", "とき", "に", "、", "そして", "挑戦", "を", "あきらめ", "た", "時", "に", "年老い", "て", "いく", "の", "だ", "と", "思い", "ます", "。", "この", "道", "を", "行け", "ば", "どう", "なる", "もの", "か", "、", "危ぶむ", "なかれ", "。", "危ぶめ", "ば", "道", "は", "なし", "。", "踏み出せ", "ば", "その", "一足", "が", "道", "と", "なる", "。", "迷わ", "ず", "行け", "よ", "。", "行け", "ば", "わかる", "さ", "。", nil]

  • 使用PC

MacBook Air
CPU: Intel Corei7 1.8GHz
Memory: 4GB
の上にVMをたてて500MBを割当て。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?