文章から名詞だけを抜き出すためにnattoを使って以下のプログラムを書きました
lang
1require 'natto' 2 3def parse_noun(word) 4 # print "version: ", MeCab::VERSION, "\n" # debug 5 6 mecab = Natto::MeCab::Tagger.new("-Ochasen") 7 node = mecab.parseToNode(word) 8 9 nouns = [] 10 while node 11 # print node.surface, "\t", node.feature, "\t", node.cost, "\n" # debug 12 13 # 名詞を抽出する 14 if /^名詞/ =~ node.feature.split(/,/)[0] then 15 nouns.push(node.surface) 16 end 17 18 node = node.next 19 end 20 21 return nouns 22end 23 24puts parse_noun("今日は雪が降っていますが、わたしは変態です。")
しかしこれを実行しても```
untitled.rb:6:in parse_noun': uninitialized constant Natto::MeCab::Tagger (NameError) from untitled.rb:24:in
<main>'
といったエラーが出てしまいます なぜでしょうか? コードは[こちらのブログ](http://hisasann.com/housetect/2010/10/rubymecab.html)をほぼコピペしています
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/05/09 02:32
2015/05/09 02:52
2015/05/09 03:20
2015/05/09 03:28