Skip to content

Instantly share code, notes, and snippets.

@panchiga
Created October 28, 2016 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panchiga/99540c9fa26ef64a291987283fdb7952 to your computer and use it in GitHub Desktop.
Save panchiga/99540c9fa26ef64a291987283fdb7952 to your computer and use it in GitHub Desktop.
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