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.



12
13
14
15
# File 'lib/pragmatic_segmenter/abbreviation_replacer.rb', line 12

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

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#replaceObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pragmatic_segmenter/abbreviation_replacer.rb', line 17

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

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