Module: Japanese::VerbIdentifier
- Included in:
- JayVerb
- Defined in:
- lib/japanese/verb_identifier.rb
Constant Summary collapse
- CONSONANT_VERBS =
List of consonant stem verbs ending in -iru
%w(脂ぎる びびる 契る 散る どじる 愚痴る 入る 走る 穿る 迸る 熱る いびる 弄る 炒る 要る 限る 齧る 呪る 切る 霧る 切る きしる 軋る 抉る 参る 混じる 交じる 滅入る 見縊る 漲る 毟る 捩じる 握る 罵る 陥る 思い入る 思い切る せびる 知る 謗る 滾る 魂消る 迸る とちる 野次る 過る 横切る 嘲る 駄弁る 彫る 選る 啁る 耽る 伏せる 侍る 減る 撚る 翻る 火照る 帰る 返る 反る 還る 孵る 陰る 駆ける 蹴る くねる 覆る 練る のめる 滑る 阿る 競る 挵る 喋る 茂る 湿気る そべる 滑る 猛る 照る 抓める 抓る うねる 蘇る 甦る 放る 括る 抉る 捥る 捩る 詰る )
- RU_IRREGULAR_MAPPING =
{ "する": "v-suru", "来る": "v-kuru", "有る": "v-aru", "ある": "v-aru", "居らっしゃる": "v5r-i", "いらっしゃる": "v5r-i" }
- AMBIGUITY_IF_HIRAGANA_ONLY =
%w(いる きる える へる かえる ねる しめる)
- E_HIRAGANA =
%w(え け せ て へ ね め れ げ ぜ で べ ぺ)
- I_HIRAGANA =
%w(い き し ち ひ に み り ぎ じ ぢぃ び ぴ)
Instance Method Summary collapse
-
#ambiguous? ⇒ Boolean
Returns true if the class of the verb cannot be determined without more information.
- #ends_in_iru_eru? ⇒ Boolean
-
#ends_in_ru? ⇒ Boolean
Include into the word class and use on word instances.
-
#irregular? ⇒ Boolean
Verifies the verb is not a “ru” irregular.
- #is_consonant_verb? ⇒ Boolean
- #resolve_ru_verb_class ⇒ Object
- #resolve_verb_class ⇒ Object
Instance Method Details
#ambiguous? ⇒ Boolean
Returns true if the class of the verb cannot be determined without more information
91 92 93 |
# 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? ⇒ Boolean
95 96 97 |
# 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? ⇒ Boolean
Include into the word class and use on word instances
82 83 84 85 86 87 88 |
# 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? ⇒ Boolean
Verifies the verb is not a “ru” irregular
106 107 108 109 110 |
# 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? ⇒ Boolean
99 100 101 102 103 |
# 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 ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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 ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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 |