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.

Constant Summary collapse

SENTENCE_STARTERS =
%w(A Being Did For He How However I In It Millions More She That The There They We What When Where Who Why)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, language: Languages::Common) ⇒ AbbreviationReplacer

Returns a new instance of AbbreviationReplacer.



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

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

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#replaceObject



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

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

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