131 lines
3.0 KiB
Ruby
131 lines
3.0 KiB
Ruby
U_VOWEL_CHANGES = {
|
|
"る" => { "a" => "ら", "i" => "り", "u" => "る", "e" => "れ", "o" => "ろ" },
|
|
"う" => { "a" => "あ", "i" => "い", "u" => "う", "e" => "え", "o" => "お" },
|
|
"つ" => { "a" => "た", "i" => "ち", "u" => "つ", "e" => "て", "o" => "と" },
|
|
"す" => { "a" => "さ", "i" => "し", "u" => "す", "e" => "せ", "o" => "そ" },
|
|
"く" => { "a" => "か", "i" => "き", "u" => "く", "e" => "け", "o" => "こ" },
|
|
"ぐ" => { "a" => "が", "i" => "ぎ", "u" => "ぐ", "e" => "げ", "o" => "ご" },
|
|
"ぶ" => { "a" => "ば", "i" => "び", "u" => "ぶ", "e" => "べ", "o" => "ぼ" },
|
|
"む" => { "a" => "ま", "i" => "み", "u" => "む", "e" => "め", "o" => "も" },
|
|
"ぬ" => { "a" => "な", "i" => "に", "u" => "ぬ", "e" => "ね", "o" => "の" },
|
|
}
|
|
|
|
class KanaKanji
|
|
attr_reader :kana, :kanji
|
|
def initialize(kana, kanji=nil)
|
|
@kana = kana
|
|
@kanji = kanji || kana
|
|
end
|
|
|
|
def [] (index)
|
|
self.class.new kana[index], kanji[index]
|
|
end
|
|
|
|
def + (other)
|
|
self.class.new kana + other, kanji + other
|
|
end
|
|
|
|
def last_character(new_form=nil)
|
|
return kana[-1] unless new_form
|
|
U_VOWEL_CHANGES[kana[-1]][new_form]
|
|
end
|
|
|
|
def all_but_last_character
|
|
self.class.new kana[0...-1], kanji[0...-1]
|
|
end
|
|
end
|
|
|
|
class Verb
|
|
attr_reader :dict_kanji, :dict_kana, :definition_english, :dict
|
|
|
|
def initialize(dict_kanji, dict_kana, definition_english)
|
|
@dict_kanji = dict_kanji || dict_kana
|
|
@dict_kana = dict_kana
|
|
@dict = KanaKanji.new dict_kana, dict_kanji
|
|
@definition_english = definition_english
|
|
end
|
|
|
|
def last_character(new_form=nil)
|
|
dict.last_character(new_form)
|
|
end
|
|
|
|
def all_but_last_character
|
|
dict.all_but_last_character
|
|
end
|
|
|
|
def ve
|
|
VerbExpression
|
|
end
|
|
|
|
def dictionary
|
|
dict
|
|
end
|
|
end
|
|
|
|
class IchidanVerb < Verb
|
|
def long_form_present_positive
|
|
all_but_last_character + "ます"
|
|
end
|
|
|
|
def long_form_present_negative
|
|
all_but_last_character + "ません"
|
|
end
|
|
|
|
def te
|
|
all_but_last_character + "て"
|
|
end
|
|
end
|
|
|
|
class GodanVerb < Verb
|
|
def long_form_present_positive
|
|
all_but_last_character + last_character("i") + "ます"
|
|
end
|
|
|
|
def long_form_present_negative
|
|
all_but_last_character + last_character("i") + "ません"
|
|
end
|
|
|
|
def te
|
|
case last_character
|
|
when "う"
|
|
all_but_last_character + "って"
|
|
when "る"
|
|
all_but_last_character + "って"
|
|
when "つ"
|
|
all_but_last_character + "って"
|
|
when "す"
|
|
all_but_last_character + "して"
|
|
when "く"
|
|
all_but_last_character + "いて"
|
|
when "ぐ"
|
|
all_but_last_character + "いで"
|
|
when "ぶ"
|
|
all_but_last_character + "んで"
|
|
when "む"
|
|
all_but_last_character + "んで"
|
|
when "ぬ"
|
|
all_but_last_character + "んで"
|
|
end
|
|
end
|
|
end
|
|
|
|
class SuruVerb < Verb
|
|
def prefix
|
|
dict[..-3]
|
|
end
|
|
|
|
def long_form_present_positive
|
|
prefix + "します"
|
|
end
|
|
|
|
def long_form_present_negative
|
|
prefix + "しません"
|
|
end
|
|
|
|
|
|
def te
|
|
prefix + "して"
|
|
end
|
|
end
|
|
|