Skip to content
Brooke M. Fujita edited this page Feb 10, 2015 · 1 revision

N-Best 読み

Obtain the 2 best readings for given kanji (同字異音異義語)

Natto::MeCab can also iterate through a list of kanji and obtain their most probable readings, using the yomi option for output_format_type and specifying output of the 2 nbest candidate readings:

nm = Natto::MeCab.new('-Oyomi -N2')
=> #<Natto::MeCab:0x288f6d08 
     @tagger=#<FFI::Pointer address=0x28d3ab80>,  
     @libpath="/usr/local/lib/libmecab.so",        
     @options={:output_format_type=>"yomi", :nbest=>2},  
     @dicts=[#<Natto::DictionaryInfo:0x288f6ba0 
              @filepath="/usr/local/lib/mecab/dic/ipadic/sys.dic", 
              charset=utf-8,
              type=0>],  
     @version=0.996>

%w( 日本語 大人気 初心 ).each do |kanji|
  puts "#{nm.parse(kanji)}\n"
end

ニホンゴ
ニッポンゴ

ダイニンキ
オトナゲ

ショシン
ウブ

Previous | Usage Top | Next

Clone this wiki locally