Skip to content

Instantly share code, notes, and snippets.

@kaiinui
Created May 30, 2014 12:10
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 kaiinui/f4c9131c30d9b7bc5b52 to your computer and use it in GitHub Desktop.
Save kaiinui/f4c9131c30d9b7bc5b52 to your computer and use it in GitHub Desktop.
#- 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
@kaiinui
Copy link
Author

kaiinui commented May 30, 2014

MeCab環境productionに作るの面倒なのでYahoo!形態素を使うことにした
残骸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment