class Ununiga::JosaPicker
한글 조사 변경 클래스
Constants
- JOSAS
Attributes
korean_str[R]
Public Class Methods
new(str)
click to toggle source
# File lib/ununiga/josa_picker.rb, line 22 def initialize(str) @korean_str = str end
takewell(str)
click to toggle source
# File lib/ununiga/josa_picker.rb, line 17 def takewell(str) new(str).takewell end
Public Instance Methods
josas()
click to toggle source
# File lib/ununiga/josa_picker.rb, line 39 def josas res = [] korean_str.scan josa_regexp do |matched| res << [$~.offset(0)[0], JOSAS.find { |josa| josa.include? matched[0] }] end res end
takewell()
click to toggle source
# File lib/ununiga/josa_picker.rb, line 26 def takewell korean_str.gsub josa_regexp do |matched| index = $~.offset(0)[0] if index == 0 matched else josa = JOSAS.find { |jo| josa_convension(jo).include? matched } splitter = JasoSplitter.new(korean_str[index - 1]) josa[(splitter.jongsung ? 0 : 1)] end end end
Private Instance Methods
josa_convension(josa)
click to toggle source
# File lib/ununiga/josa_picker.rb, line 60 def josa_convension(josa) if josa[0].size == 1 ["#{josa[0]}(#{josa[1]})", "#{josa[1]}(#{josa[0]})"] elsif josa[0].size == 2 ["(#{josa[0][0]})#{josa[1]}"] end end
josa_regexp()
click to toggle source
# File lib/ununiga/josa_picker.rb, line 49 def josa_regexp @_josa_regexp ||= begin josa_regexp_seq = JOSAS.map do |josa| conv = josa_convension(josa) conv.map { |str| str.gsub!('(', '\\(').gsub!(')', '\\)') } end Regexp.new(josa_regexp_seq.flatten.join('|')) end end