Class: Langue::Japanese::Shaper
- Inherits:
-
Object
- Object
- Langue::Japanese::Shaper
- Includes:
- Logging
- Defined in:
- lib/langue/japanese/shaper.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Shaper
constructor
A new instance of Shaper.
- #shape_person_name(morphemes, person_name) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(options = {}) ⇒ Shaper
Returns a new instance of Shaper.
11 12 13 |
# File 'lib/langue/japanese/shaper.rb', line 11 def initialize( = {}) @logger = [:logger] || null_logger end |
Instance Method Details
#shape_person_name(morphemes, person_name) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/langue/japanese/shaper.rb', line 15 def shape_person_name(morphemes, person_name) Morphemes.new.tap do |new_morphemes| person_name_morphemes = [] start_index = 0 person_name_size = person_name.size morphemes.each do |morpheme| text = morpheme.text index = person_name.index(text, start_index) if index == start_index person_name_morphemes << morpheme start_index += text.size if start_index == person_name_size new_morphemes << join_as_person_name(person_name_morphemes) person_name_morphemes.clear start_index = 0 end else new_morphemes.concat(person_name_morphemes) << morpheme person_name_morphemes.clear start_index = 0 end end end end |