class JumanppRuby::Juman
Public Class Methods
help()
click to toggle source
# File lib/jumanpp_ruby.rb, line 41 def self.help o, = Open3.capture2('jumanpp -h') o.strip end
new(beam: nil, force_single_path: false, partial: false)
click to toggle source
# File lib/jumanpp_ruby.rb, line 9 def initialize(beam: nil, force_single_path: false, partial: false) argv = ['jumanpp'] argv << '--beam' << beam if beam argv << '--force-single-path' if force_single_path argv << '--partial' if partial @pipe = IO.popen(argv, 'r+') end
version()
click to toggle source
# File lib/jumanpp_ruby.rb, line 36 def self.version o, = Open3.capture2('jumanpp -v') o.strip end
Public Instance Methods
close()
click to toggle source
# File lib/jumanpp_ruby.rb, line 32 def close @pipe.close end
parse(sentents) { |word| ... }
click to toggle source
# File lib/jumanpp_ruby.rb, line 17 def parse(sentents) @pipe.puts(zh_convert(sentents)) responses = [] while sentent = @pipe.gets a = sentent.scan(/(?:\\ |[^\s"]|"[^"]*")+/) a.each {|i| i.sub!(/\A"(.*)"\z/, '\\1') } responses << a break if sentent =~ /EOS\n/ end if block_given? responses.each { |word| yield word } else responses.map { |word| word.first } end end
Private Instance Methods
zh_convert(str)
click to toggle source
# File lib/jumanpp_ruby.rb, line 48 def zh_convert str str.tr <<~'STR1',<<~'STR2' ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ STR1 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 !”#$%&’()*+,−./:;<=>?@[¥]^_`{|}〜 STR2 end