Class: PragmaticSegmenter::AbbreviationReplacer

Inherits:
Object
  • Object
show all
Defined in:
lib/pragmatic_segmenter/abbreviation_replacer.rb

Overview

This class searches for periods within an abbreviation and replaces the periods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, language:) ⇒ AbbreviationReplacer

Returns a new instance of AbbreviationReplacer.



9
10
11
12
# File 'lib/pragmatic_segmenter/abbreviation_replacer.rb', line 9

def initialize(text:, language: )
  @text = Text.new(text)
  @language = language
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



8
9
10
# File 'lib/pragmatic_segmenter/abbreviation_replacer.rb', line 8

def text
  @text
end

Instance Method Details

#replaceObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/pragmatic_segmenter/abbreviation_replacer.rb', line 14

def replace
  @text.apply(@language::PossessiveAbbreviationRule,
    @language::KommanditgesellschaftRule,
    @language::SingleLetterAbbreviationRules::All)

  @text = search_for_abbreviations_in_string(@text)
  @text = replace_multi_period_abbreviations(@text)
  @text.apply(@language::AmPmRules::All)
  replace_abbreviation_as_sentence_boundary(@text)
end