LoginSignup
5
2

More than 5 years have passed since last update.

rubyで自然言語処理(natto)を使ってみた @cloud9

Last updated at Posted at 2017-09-27

環境設定

nattoを使うためにはmecabをインストールしなければならない

$ sudo apt-get update
$ sudo apt-get install -y mecab mecab-ipadic-utf8 libc6-dev build-essential libmecab-dev libfreetype6-dev libxft-dev

mecabコマンドを使う

$ mecab 
こんにちは今日は晴れです!
こんにちは      感動詞,*,*,*,*,*,こんにちは,コンニチハ,コンニチワ
今日    名詞,副詞可能,*,*,*,*,今日,キョウ,キョー
は      助詞,係助詞,*,*,*,*,は,ハ,ワ
晴れ    名詞,一般,*,*,*,*,晴れ,ハレ,ハレ
です    助動詞,*,*,*,特殊・デス,基本形,です,デス,デス
!      記号,一般,*,*,*,*,!,!,!
EOS

rubyの準備

test.rbでnattoを使うサンプルプログラムを作成した。

test.rb
require 'natto'

nm = Natto::MeCab.new

text = '太郎はこの本を二郎を見た女性に渡した。'
nm.parse(text) do |n|
  puts " >> #{n.surface} \t>> #{n.feature}"
end

環境構築を行い。実行する。

$ gem install bundler
$ bundle init 
$ echo "gem 'natto'" >> Gemfile
$ bundle
$ ruby test.rb

参照

[Ruby]mecabを使ってみた(形態素解析)

Python MeCabをCloud9上で動かす|Review of My Life

5
2
2

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
5
2