module Japanese::VerbIdentifier

Constants

AMBIGUITY_IF_HIRAGANA_ONLY
CONSONANT_VERBS

List of consonant stem verbs ending in -iru

E_HIRAGANA
I_HIRAGANA
RU_IRREGULAR_MAPPING

Public Instance Methods

ambiguous?() click to toggle source

Returns true if the class of the verb cannot be determined without more information

# File lib/japanese/verb_identifier.rb, line 91
def ambiguous?
  self.kanji == self.hiragana && self.kanji.in?(AMBIGUITY_IF_HIRAGANA_ONLY) ? true : false
end
ends_in_iru_eru?() click to toggle source
# File lib/japanese/verb_identifier.rb, line 95
def ends_in_iru_eru?
  self.hiragana[-2].in?(E_HIRAGANA) || self.hiragana[-2].in?(I_HIRAGANA) ? true : false
end
ends_in_ru?() click to toggle source

Include into the word class and use on word instances

# File lib/japanese/verb_identifier.rb, line 82
def ends_in_ru?
  unless self.kanji.blank?
    self.kanji[-1] == "る" ? true : false
  else 
    self.hiragana[-1] == "る" ? true : false
  end
end
irregular?() click to toggle source

Verifies the verb is not a “ru” irregular

# File lib/japanese/verb_identifier.rb, line 106
def irregular?
  irregulars = RU_IRREGULAR_MAPPING.stringify_keys!
  ireg = irregulars.keys
  self.kanji.in?(ireg) ? true : false
end
is_consonant_verb?() click to toggle source
# File lib/japanese/verb_identifier.rb, line 99
def is_consonant_verb?
  if self.ends_in_iru_eru? && !ambiguous?
    self.kanji.in?(CONSONANT_VERBS) ? true : false
  end
end
resolve_ru_verb_class() click to toggle source
# File lib/japanese/verb_identifier.rb, line 33
def resolve_ru_verb_class
  return nil if ambiguous?
  unless irregular?
    if ends_in_iru_eru? && is_consonant_verb?
      self.part_of_speech = "v5r"
    elsif ends_in_ru? && !ends_in_iru_eru?
      self.part_of_speech = "v5r"
    elsif ends_in_iru_eru? && !is_consonant_verb?
      self.part_of_speech = "v1"
    end
  else
    RU_IRREGULAR_MAPPING.stringify_keys!
    RU_IRREGULAR_MAPPING.each do |k, v|
      self.part_of_speech = v if self.kanji == k
    end
  end
end
resolve_verb_class() click to toggle source
# File lib/japanese/verb_identifier.rb, line 51
def resolve_verb_class
  # Check if the word is a special case of "k" or "u" verb
  if self.kanji == "行く"
    self.part_of_speech = "v5k-s"
  elsif self.kanji == "問う"
    self.part_of_speech = "v5u-s"
  else
    case self.kanji[-1]
      when "ぶ"
        self.part_of_speech = "v5b"
      when "ぐ"
        self.part_of_speech = "v5g"
      when "く"
        self.part_of_speech = "v5k" unless self.kanji == "行く"
      when "む"
        self.part_of_speech = "v5m"
      when "ぬ"
        self.part_of_speech = "v5n"
      when "す"
        self.part_of_speech = "v5s"
      when "る"
        resolve_ru_verb_class
      when "つ"
        self.part_of_speech = "v5t"
      when "う"
        self.part_of_speech = "v5u" unless self.kanji == "問う"
    end
  end
end