class WordCountAnalyzer::Contraction

Constants

CONTRACTIONS

Attributes

following_token[R]
hyphen[R]
tgr[R]
token[R]

Public Class Methods

new(token:, following_token:, tgr:, **args) click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 87
def initialize(token:, following_token:, tgr:, **args)
  @token = token
  @following_token = following_token
  @tgr = tgr
  @hyphen = args[:hyphen] || 'count_as_one'
end

Public Instance Methods

contraction?() click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 94
def contraction?
  common_contraction? ||
  (apostrophe_s_token? &&
    following_is_not_a_noun?)
end
expanded_count() click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 100
def expanded_count
  if self.contraction?
    if common_contraction?
      calculate_contraction_length
    else
      2
    end
  else
    1
  end
end
replace() click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 112
def replace
  if CONTRACTIONS.has_key?(token.downcase)
    CONTRACTIONS[token.downcase]
  elsif apostrophe_s_token? && following_is_not_a_noun?
    ' word word '
  else
    token
  end
end

Private Instance Methods

apostrophe_s_token?() click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 148
def apostrophe_s_token?
  token.include?("'s")
end
calculate_contraction_length() click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 124
def calculate_contraction_length
  if hyphen.eql?('count_as_one') && hyphen
    contraction_length
  else
    contraction_length_hyphen
  end
end
common_contraction?() click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 140
def common_contraction?
  CONTRACTIONS.has_key?(token.downcase)
end
contraction_length() click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 132
def contraction_length
  CONTRACTIONS[token.downcase].split(' ').length
end
contraction_length_hyphen() click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 136
def contraction_length_hyphen
  CONTRACTIONS[token.downcase].split(' ').map { |token| token.split('-') }.flatten.length
end
following_is_not_a_noun?() click to toggle source
# File lib/word_count_analyzer/contraction.rb, line 144
def following_is_not_a_noun?
  !tgr.add_tags(following_token)[1].downcase.eql?('n')
end