Create a gist now

Instantly share code, notes, and snippets.

require 'mecab'
sentence = "ゲームしてからスケベしよう"
mecab = MeCab::Tagger.new
node = mecab.parseToNode(sentence)
word_array = []
begin
node = node.next
if /^名詞/ =~ node.feature.force_encoding("UTF-8")
word_array << node.surface.force_encoding("UTF-8")
end
end until node.next.feature.include?("BOS/EOS")
p word_array
#=>
#["ゲーム", "スケベ"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment