Method: Ja::ComplexWord#to_nodes

Defined in:
lib/ja/complex_word.rb

#to_nodes(text) ⇒ Object

MeCab を用いて日本語テキストを解析し MeCab::Node 風の OpenStruct オブジェクトを含む配列にして返す。形態素が未知の場合には :unk オプションに指定された文字列 (デフォルトは「未知語」) を利用し、素性を ‘未知語,’ に設定する。



47
48
49
50
51
52
53
54
55
56
# File 'lib/ja/complex_word.rb', line 47

def to_nodes(text)
  list = []
  tagger = MeCab::Tagger.new("-U %M\\t#{@opts[:unk]},\\n")
  result = tagger.parse(text)
  result.split("\n").each do |line|
    surface, feature = line.chomp.split("\t")
    list << OpenStruct.new(:surface => surface, :feature => feature || '')
  end
  list
end