Class: PragmaticSegmenter::PunctuationReplacer

Inherits:
Object
  • Object
show all
Includes:
Rules
Defined in:
lib/pragmatic_segmenter/punctuation_replacer.rb

Overview

This class replaces punctuation that is typically a sentence boundary but in this case is not a sentence boundary.

Constant Summary collapse

BETWEEN_SINGLE_QUOTES_REGEX =
/(?<=\s)'(?:[^']|'[a-zA-Z])*'/

Constants included from Rules

Rules::AbbreviationsWithMultiplePeriodsAndEmailRule, Rules::ConsecutiveForwardSlashRule, Rules::ConsecutivePeriodsRule, Rules::DoubleNewLineRule, Rules::DoubleNewLineWithSpaceRule, Rules::EscapedCarriageReturnRule, Rules::EscapedNewLineRule, Rules::ExtraWhiteSpaceRule, Rules::GeoLocationRule, Rules::InlineFormattingRule, Rules::NEWLINE_IN_MIDDLE_OF_SENTENCE_REGEX, Rules::NO_SPACE_BETWEEN_SENTENCES_DIGIT_REGEX, Rules::NO_SPACE_BETWEEN_SENTENCES_REGEX, Rules::NewLineFollowedByBulletRule, Rules::NewLineFollowedByPeriodRule, Rules::NewLineInMiddleOfWordRule, Rules::NoSpaceBetweenSentencesDigitRule, Rules::NoSpaceBetweenSentencesRule, Rules::PDF_NewLineInMiddleOfSentenceNoSpacesRule, Rules::PDF_NewLineInMiddleOfSentenceRule, Rules::QuestionMarkInQuotationRule, Rules::QuotationsFirstRule, Rules::QuotationsSecondRule, Rules::ReplaceNewlineWithCarriageReturnRule, Rules::SingleNewLineRule, Rules::SubSingleQuoteRule, Rules::TableOfContentsRule, Rules::TypoEscapedCarriageReturnRule, Rules::TypoEscapedNewLineRule, Rules::URL_EMAIL_KEYWORDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, matches_array:, **args) ⇒ PunctuationReplacer

Returns a new instance of PunctuationReplacer.



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

def initialize(text:, matches_array:, **args)
  @text = text
  @matches_array = matches_array
  @match_type = args[:match_type]
end

Instance Attribute Details

#match_typeObject (readonly)

Returns the value of attribute match_type.



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

def match_type
  @match_type
end

#matches_arrayObject (readonly)

Returns the value of attribute matches_array.



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

def matches_array
  @matches_array
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#replaceObject



18
19
20
# File 'lib/pragmatic_segmenter/punctuation_replacer.rb', line 18

def replace
  replace_punctuation(matches_array, text)
end