Created
October 28, 2016 19:00
-
-
Save panchiga/99540c9fa26ef64a291987283fdb7952 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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