Created
May 30, 2014 12:10
-
-
Save kaiinui/f4c9131c30d9b7bc5b52 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
#- encode: utf-8 | |
require 'natto' | |
class Mecab | |
def self.parse(sentence) | |
mecab.parse(sentence).split(";").map {|a| a.split(":")} | |
end | |
def self.nouns(sentence) | |
nouns = parse(sentence).keep_if {|a| a[1]=="名詞"} | |
nouns.map {|a| a[0]} | |
end | |
def self.mecab | |
@mecab ||= Natto::MeCab.new(format) | |
end | |
def self.format | |
{ | |
node_format: "%m:%f[0];" | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MeCab環境productionに作るの面倒なのでYahoo!形態素を使うことにした
残骸