Class: TextRank::CharFilter::UndoContractions

Inherits:
Object
  • Object
show all
Defined in:
lib/text_rank/char_filter/undo_contractions.rb

Overview

Character filter to convert English contractions into their expanded form.

Example

UndoContractions.new.filter!("You're a bitter man. That's because I've lived.")
=> "You are a bitter man. That is because I have lived."

Constant Summary collapse

CONTRACTIONS =

List of English contractions to undo

YAML.load_file(File.expand_path('undo_contractions.yml', __dir__))

Instance Method Summary collapse

Instance Method Details

#filter!(text) ⇒ String

Perform the filter

Parameters:

  • text (String)

Returns:

  • (String)


19
20
21
22
23
# File 'lib/text_rank/char_filter/undo_contractions.rb', line 19

def filter!(text)
  text.gsub!(/[a-z']+/) do |word|
    CONTRACTIONS[word] || word
  end
end