"""
Deinflection rule definitions.

This module contains all ~400 deinflection rules ported from the TypeScript implementation.
Rules are grouped by length for efficient matching.
"""

from ._types import WordType, Reason

# Deinflection rule data: (from, to, fromType, toType, reasons)
# Rules are ordered by length (longest first) for efficient matching
DEINFLECT_RULE_DATA = [
    # -------------- 7 --------------
    ('ていらっしゃい', '', WordType.Initial, WordType.TaTeStem, [Reason.Respectful, Reason.Continuous, Reason.Imperative]),
    ('ていらっしゃる', '', WordType.GodanVerb, WordType.TaTeStem, [Reason.Respectful, Reason.Continuous]),
    ('でいらっしゃい', '', WordType.Initial, WordType.DaDeStem, [Reason.Respectful, Reason.Continuous, Reason.Imperative]),
    ('でいらっしゃる', '', WordType.GodanVerb, WordType.DaDeStem, [Reason.Respectful, Reason.Continuous]),
    # -------------- 6 --------------
    ('いらっしゃい', 'いらっしゃる', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('いらっしゃい', 'いらっしゃる', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('くありません', 'い', WordType.Initial, WordType.IAdj, [Reason.PoliteNegative]),
    ('ざるをえない', '', WordType.IAdj, WordType.IrrealisStem, [Reason.ZaruWoEnai]),
    ('ざるを得ない', '', WordType.IAdj, WordType.IrrealisStem, [Reason.ZaruWoEnai]),
    ('ませんでした', '', WordType.Initial, WordType.MasuStem, [Reason.PolitePastNegative]),
    ('てらっしゃい', '', WordType.Initial, WordType.TaTeStem, [Reason.Respectful, Reason.Continuous, Reason.Imperative]),
    ('てらっしゃい', 'てらっしゃる', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('てらっしゃる', '', WordType.GodanVerb, WordType.TaTeStem, [Reason.Respectful, Reason.Continuous]),
    ('でらっしゃい', '', WordType.Initial, WordType.DaDeStem, [Reason.Respectful, Reason.Continuous, Reason.Imperative]),
    ('でらっしゃい', 'でらっしゃる', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('でらっしゃる', '', WordType.GodanVerb, WordType.DaDeStem, [Reason.Respectful, Reason.Continuous]),
    # -------------- 5 --------------
    ('おっしゃい', 'おっしゃる', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('おっしゃい', 'おっしゃる', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('ざるえない', '', WordType.IAdj, WordType.IrrealisStem, [Reason.ZaruWoEnai]),
    ('ざる得ない', '', WordType.IAdj, WordType.IrrealisStem, [Reason.ZaruWoEnai]),
    ('ざるをえぬ', '', WordType.IAdj, WordType.IrrealisStem, [Reason.ZaruWoEnai]),
    ('ざるを得ぬ', '', WordType.IAdj, WordType.IrrealisStem, [Reason.ZaruWoEnai]),
    # -------------- 4 --------------
    ('かったら', 'い', WordType.Initial, WordType.IAdj, [Reason.Tara]),
    ('かったり', 'い', WordType.Initial, WordType.IAdj, [Reason.Tari]),
    ('ください', 'くださる', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('ください', 'くださる', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('こさせる', 'くる', WordType.IchidanVerb, WordType.KuruVerb, [Reason.Causative]),
    ('こられる', 'くる', WordType.IchidanVerb, WordType.KuruVerb, [Reason.PotentialOrPassive]),
    ('さないで', 'する', WordType.Initial, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.NegativeTe]),
    ('ざるえぬ', '', WordType.IAdj, WordType.IrrealisStem, [Reason.ZaruWoEnai]),
    ('ざる得ぬ', '', WordType.IAdj, WordType.IrrealisStem, [Reason.ZaruWoEnai]),
    ('しないで', 'する', WordType.Initial, WordType.SuruVerb, [Reason.NegativeTe]),
    ('しさせる', 'する', WordType.IchidanVerb, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Causative]),
    ('しられる', 'する', WordType.IchidanVerb, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.PotentialOrPassive]),
    ('せさせる', 'する', WordType.IchidanVerb, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Causative]),
    ('せられる', 'する', WordType.IchidanVerb, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.PotentialOrPassive]),
    ('ぜさせる', 'ずる', WordType.IchidanVerb, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Causative]),
    ('ぜられる', 'ずる', WordType.IchidanVerb, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.PotentialOrPassive]),
    ('たゆたう', 'たゆたう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('たゆとう', 'たゆとう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('のたまう', 'のたまう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('のたもう', 'のたもう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('ましたら', '', WordType.Initial, WordType.MasuStem, [Reason.Polite, Reason.Tara]),
    ('ましたり', '', WordType.Initial, WordType.MasuStem, [Reason.Polite, Reason.Tari]),
    ('ましょう', '', WordType.Initial, WordType.MasuStem, [Reason.PoliteVolitional]),
    # -------------- 3 --------------
    ('いたす', '', WordType.GodanVerb, WordType.MasuStem, [Reason.Humble]),
    ('いたす', '', WordType.GodanVerb, WordType.NounVS, [Reason.SuruNoun, Reason.Humble]),
    ('かった', 'い', WordType.Initial, WordType.IAdj, [Reason.Past]),
    ('下さい', '下さる', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('下さい', '下さる', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('くない', 'い', WordType.IAdj, WordType.IAdj, [Reason.Negative]),
    ('ければ', 'い', WordType.Initial, WordType.IAdj, [Reason.Ba]),
    ('こよう', 'くる', WordType.Initial, WordType.KuruVerb, [Reason.Volitional]),
    ('これる', 'くる', WordType.IchidanVerb, WordType.KuruVerb, [Reason.Potential]),
    ('来れる', '来る', WordType.IchidanVerb, WordType.KuruVerb, [Reason.Potential]),
    ('來れる', '來る', WordType.IchidanVerb, WordType.KuruVerb, [Reason.Potential]),
    ('ござい', 'ござる', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('ご座い', 'ご座る', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('御座い', '御座る', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('させる', 'る', WordType.IchidanVerb, WordType.IchidanVerb | WordType.KuruVerb, [Reason.Causative]),
    ('させる', 'する', WordType.IchidanVerb, WordType.SuruVerb, [Reason.Causative]),
    ('さない', 'する', WordType.IAdj, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Negative]),
    ('される', '', WordType.IchidanVerb, WordType.IrrealisStem, [Reason.CausativePassive]),
    ('される', 'する', WordType.IchidanVerb, WordType.SuruVerb, [Reason.Passive]),
    ('しうる', 'する', WordType.Initial, WordType.SuruVerb, [Reason.EruUru]),
    ('しえる', 'する', WordType.IchidanVerb, WordType.SuruVerb, [Reason.EruUru]),
    ('しない', 'する', WordType.IAdj, WordType.SuruVerb, [Reason.Negative]),
    ('しよう', 'する', WordType.Initial, WordType.SuruVerb, [Reason.Volitional]),
    ('じゃう', '', WordType.GodanVerb, WordType.DaDeStem, [Reason.Chau]),
    ('すぎる', 'い', WordType.IchidanVerb, WordType.IAdj, [Reason.Sugiru]),
    ('すぎる', '', WordType.IchidanVerb, WordType.MasuStem, [Reason.Sugiru]),
    ('過ぎる', 'い', WordType.IchidanVerb, WordType.IAdj, [Reason.Sugiru]),
    ('過ぎる', '', WordType.IchidanVerb, WordType.MasuStem, [Reason.Sugiru]),
    ('ずれば', 'ずる', WordType.Initial, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Ba]),
    ('たまう', 'たまう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('たもう', 'たもう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('揺蕩う', '揺蕩う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('ちゃう', '', WordType.GodanVerb, WordType.TaTeStem, [Reason.Chau]),
    ('ている', '', WordType.IchidanVerb, WordType.TaTeStem, [Reason.Continuous]),
    ('ておる', '', WordType.GodanVerb, WordType.TaTeStem, [Reason.HumbleOrKansaiDialect, Reason.Continuous]),
    ('でいる', '', WordType.IchidanVerb, WordType.DaDeStem, [Reason.Continuous]),
    ('でおる', '', WordType.GodanVerb, WordType.DaDeStem, [Reason.HumbleOrKansaiDialect, Reason.Continuous]),
    ('できる', 'する', WordType.IchidanVerb, WordType.SuruVerb, [Reason.Potential]),
    ('ないで', '', WordType.Initial, WordType.IrrealisStem, [Reason.NegativeTe]),
    ('なさい', '', WordType.Initial, WordType.MasuStem, [Reason.Respectful, Reason.Imperative]),
    ('なさい', 'なさる', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('なさい', 'なさる', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('なさる', '', WordType.GodanVerb, WordType.MasuStem, [Reason.Respectful]),
    ('なさる', '', WordType.GodanVerb, WordType.NounVS, [Reason.SuruNoun, Reason.Respectful]),
    ('になる', '', WordType.GodanVerb, WordType.MasuStem, [Reason.Respectful]),
    ('になる', '', WordType.GodanVerb, WordType.NounVS, [Reason.SuruNoun, Reason.Respectful]),
    ('ました', '', WordType.Initial, WordType.MasuStem, [Reason.PolitePast]),
    ('まして', '', WordType.Initial, WordType.MasuStem, [Reason.Polite, Reason.Te]),
    ('ません', '', WordType.Initial, WordType.MasuStem, [Reason.PoliteNegative]),
    ('られる', 'る', WordType.IchidanVerb, WordType.IchidanVerb | WordType.KuruVerb, [Reason.PotentialOrPassive]),
    # -------------- 2 --------------
    ('致す', '', WordType.GodanVerb, WordType.MasuStem, [Reason.Humble]),
    ('致す', '', WordType.GodanVerb, WordType.NounVS, [Reason.SuruNoun, Reason.Humble]),
    ('えば', 'う', WordType.Initial, WordType.GodanVerb, [Reason.Ba]),
    ('える', 'う', WordType.IchidanVerb, WordType.GodanVerb, [Reason.Potential]),
    ('得る', '', WordType.IchidanVerb, WordType.MasuStem, [Reason.EruUru]),
    ('おう', 'う', WordType.Initial, WordType.GodanVerb, [Reason.Volitional]),
    ('仰い', '仰る', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('仰い', '仰る', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('くて', 'い', WordType.Initial, WordType.IAdj, [Reason.Te]),
    ('けば', 'く', WordType.Initial, WordType.GodanVerb, [Reason.Ba]),
    ('げば', 'ぐ', WordType.Initial, WordType.GodanVerb, [Reason.Ba]),
    ('ける', 'く', WordType.IchidanVerb, WordType.GodanVerb, [Reason.Potential]),
    ('げる', 'ぐ', WordType.IchidanVerb, WordType.GodanVerb, [Reason.Potential]),
    ('こい', 'くる', WordType.Initial, WordType.KuruVerb, [Reason.Imperative]),
    ('こう', 'く', WordType.Initial, WordType.GodanVerb, [Reason.Volitional]),
    ('ごう', 'ぐ', WordType.Initial, WordType.GodanVerb, [Reason.Volitional]),
    ('しろ', 'する', WordType.Initial, WordType.SuruVerb, [Reason.Imperative]),
    ('さず', 'する', WordType.Initial, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Zu]),
    ('すぎ', 'い', WordType.Initial, WordType.IAdj, [Reason.Sugiru]),
    ('すぎ', '', WordType.Initial, WordType.MasuStem, [Reason.Sugiru]),
    ('過ぎ', 'い', WordType.Initial, WordType.IAdj, [Reason.Sugiru]),
    ('過ぎ', '', WordType.Initial, WordType.MasuStem, [Reason.Sugiru]),
    ('する', '', WordType.SuruVerb, WordType.NounVS, [Reason.SuruNoun]),
    ('せず', 'する', WordType.Initial, WordType.SuruVerb, [Reason.Zu]),
    ('せぬ', 'する', WordType.Initial, WordType.SuruVerb, [Reason.Negative]),
    ('せん', 'する', WordType.Initial, WordType.SuruVerb, [Reason.Negative]),
    ('せば', 'す', WordType.Initial, WordType.GodanVerb, [Reason.Ba]),
    ('せば', 'する', WordType.Initial, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Ba]),
    ('せよ', 'する', WordType.Initial, WordType.SuruVerb, [Reason.Imperative]),
    ('せる', 'す', WordType.IchidanVerb, WordType.GodanVerb, [Reason.Potential]),
    ('せる', '', WordType.IchidanVerb, WordType.IrrealisStem, [Reason.Causative]),
    ('ぜず', 'ずる', WordType.Initial, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Zu]),
    ('ぜぬ', 'ずる', WordType.Initial, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Negative]),
    ('ぜよ', 'ずる', WordType.Initial, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Imperative]),
    ('そう', '', WordType.Initial, WordType.MasuStem, [Reason.Sou]),
    ('そう', 'い', WordType.Initial, WordType.IAdj, [Reason.Sou]),
    ('そう', 'す', WordType.Initial, WordType.GodanVerb, [Reason.Volitional]),
    ('そう', 'する', WordType.Initial, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Volitional]),
    ('たい', '', WordType.IAdj, WordType.MasuStem, [Reason.Tai]),
    ('たら', '', WordType.Initial, WordType.TaTeStem, [Reason.Tara]),
    ('だら', '', WordType.Initial, WordType.DaDeStem, [Reason.Tara]),
    ('たり', '', WordType.Initial, WordType.TaTeStem, [Reason.Tari]),
    ('だり', '', WordType.Initial, WordType.DaDeStem, [Reason.Tari]),
    ('てば', 'つ', WordType.Initial, WordType.GodanVerb, [Reason.Ba]),
    ('てる', 'つ', WordType.IchidanVerb, WordType.GodanVerb, [Reason.Potential]),
    ('てる', '', WordType.IchidanVerb, WordType.TaTeStem, [Reason.Continuous]),
    ('でる', '', WordType.IchidanVerb, WordType.DaDeStem, [Reason.Continuous]),
    ('とう', 'つ', WordType.Initial, WordType.GodanVerb, [Reason.Volitional]),
    ('とく', '', WordType.GodanVerb, WordType.TaTeStem, [Reason.Toku]),
    ('とる', '', WordType.GodanVerb, WordType.TaTeStem, [Reason.HumbleOrKansaiDialect, Reason.Continuous]),
    ('どく', '', WordType.GodanVerb, WordType.DaDeStem, [Reason.Toku]),
    ('どる', '', WordType.GodanVerb, WordType.DaDeStem, [Reason.HumbleOrKansaiDialect, Reason.Continuous]),
    ('ない', '', WordType.IAdj, WordType.IrrealisStem, [Reason.Negative]),
    ('ねば', 'ぬ', WordType.Initial, WordType.GodanVerb, [Reason.Ba]),
    ('ねる', 'ぬ', WordType.IchidanVerb, WordType.GodanVerb, [Reason.Potential]),
    ('のう', 'ぬ', WordType.Initial, WordType.GodanVerb, [Reason.Volitional]),
    ('べば', 'ぶ', WordType.Initial, WordType.GodanVerb, [Reason.Ba]),
    ('べる', 'ぶ', WordType.IchidanVerb, WordType.GodanVerb, [Reason.Potential]),
    ('ぼう', 'ぶ', WordType.Initial, WordType.GodanVerb, [Reason.Volitional]),
    ('ます', '', WordType.Initial, WordType.MasuStem, [Reason.Polite]),
    ('ませ', '', WordType.Initial, WordType.MasuStem, [Reason.Polite, Reason.Imperative]),
    ('めば', 'む', WordType.Initial, WordType.GodanVerb, [Reason.Ba]),
    ('める', 'む', WordType.IchidanVerb, WordType.GodanVerb, [Reason.Potential]),
    ('もう', 'む', WordType.Initial, WordType.GodanVerb, [Reason.Volitional]),
    ('よう', 'る', WordType.Initial, WordType.IchidanVerb | WordType.KuruVerb, [Reason.Volitional]),
    ('れば', 'る', WordType.Initial, WordType.IchidanVerb | WordType.GodanVerb | WordType.KuruVerb | WordType.SuruVerb, [Reason.Ba]),
    ('れる', 'る', WordType.IchidanVerb, WordType.IchidanVerb | WordType.GodanVerb, [Reason.Potential]),
    ('れる', '', WordType.IchidanVerb, WordType.IrrealisStem, [Reason.Passive]),
    ('ろう', 'る', WordType.Initial, WordType.GodanVerb, [Reason.Volitional]),
    # Irregular て-form stems
    ('いっ', 'いく', WordType.TaTeStem, WordType.GodanVerb, []),
    ('おう', 'おう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('こう', 'こう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('そう', 'そう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('とう', 'とう', WordType.TaTeStem, WordType.GodanVerb, []),
    ('行っ', '行く', WordType.TaTeStem, WordType.GodanVerb, []),
    ('逝っ', '逝く', WordType.TaTeStem, WordType.GodanVerb, []),
    ('往っ', '往く', WordType.TaTeStem, WordType.GodanVerb, []),
    ('請う', '請う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('乞う', '乞う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('恋う', '恋う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('問う', '問う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('負う', '負う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('沿う', '沿う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('添う', '添う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('副う', '副う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('厭う', '厭う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('給う', '給う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('賜う', '賜う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('宣う', '宣う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('曰う', '曰う', WordType.TaTeStem, WordType.GodanVerb, []),
    # -------------- 1 --------------
    ('い', 'う', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('い', 'く', WordType.TaTeStem, WordType.GodanVerb, []),
    ('い', 'ぐ', WordType.DaDeStem, WordType.GodanVerb, []),
    ('い', 'る', WordType.Initial, WordType.KuruVerb, [Reason.Imperative]),
    ('え', 'う', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('か', 'く', WordType.IrrealisStem, WordType.GodanVerb, []),
    ('が', 'ぐ', WordType.IrrealisStem, WordType.GodanVerb, []),
    ('き', 'い', WordType.Initial, WordType.IAdj, [Reason.Ki]),
    ('き', 'く', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('き', 'くる', WordType.TaTeStem, WordType.KuruVerb, []),
    ('き', 'くる', WordType.MasuStem, WordType.KuruVerb, [Reason.MasuStem]),
    ('ぎ', 'ぐ', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('く', 'い', WordType.Initial, WordType.IAdj, [Reason.Adv]),
    ('け', 'く', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('げ', 'ぐ', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('こ', 'くる', WordType.IrrealisStem, WordType.KuruVerb, []),
    ('さ', 'い', WordType.Initial, WordType.IAdj, [Reason.Noun]),
    ('さ', 'す', WordType.IrrealisStem, WordType.GodanVerb, []),
    ('し', 'す', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('し', 'する', WordType.MasuStem, WordType.SuruVerb, [Reason.MasuStem]),
    ('し', 'す', WordType.TaTeStem, WordType.GodanVerb, []),
    ('し', 'する', WordType.TaTeStem, WordType.SuruVerb, []),
    ('ず', '', WordType.Initial, WordType.IrrealisStem, [Reason.Zu]),
    ('せ', 'す', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('せ', 'する', WordType.Initial, WordType.SpecialSuruVerb, [Reason.Irregular, Reason.Imperative]),
    ('た', 'つ', WordType.IrrealisStem, WordType.GodanVerb, []),
    ('た', '', WordType.Initial, WordType.TaTeStem, [Reason.Past]),
    ('だ', '', WordType.Initial, WordType.DaDeStem, [Reason.Past]),
    ('ち', 'つ', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('っ', 'う', WordType.TaTeStem, WordType.GodanVerb, []),
    ('っ', 'つ', WordType.TaTeStem, WordType.GodanVerb, []),
    ('っ', 'る', WordType.TaTeStem, WordType.GodanVerb, []),
    ('て', '', WordType.Initial, WordType.TaTeStem, [Reason.Te]),
    ('て', 'つ', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('で', '', WordType.Initial, WordType.DaDeStem, [Reason.Te]),
    ('な', 'ぬ', WordType.IrrealisStem, WordType.GodanVerb, []),
    ('な', '', WordType.Initial, WordType.IchidanVerb | WordType.GodanVerb | WordType.KuruVerb | WordType.SuruVerb, [Reason.ImperativeNegative]),
    ('に', 'ぬ', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('ぬ', '', WordType.Initial, WordType.IrrealisStem, [Reason.Negative]),
    ('ね', 'ぬ', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('ば', 'ぶ', WordType.IrrealisStem, WordType.GodanVerb, []),
    ('び', 'ぶ', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('べ', 'ぶ', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('ま', 'む', WordType.IrrealisStem, WordType.GodanVerb, []),
    ('み', 'む', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('め', 'む', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('よ', 'る', WordType.Initial, WordType.IchidanVerb, [Reason.Imperative]),
    ('ら', 'る', WordType.IrrealisStem, WordType.GodanVerb, []),
    ('り', 'る', WordType.MasuStem, WordType.GodanVerb, [Reason.MasuStem]),
    ('れ', 'る', WordType.Initial, WordType.GodanVerb, [Reason.Imperative]),
    ('ろ', 'る', WordType.Initial, WordType.IchidanVerb, [Reason.Imperative]),
    ('わ', 'う', WordType.IrrealisStem, WordType.GodanVerb, []),
    ('ん', 'ぬ', WordType.DaDeStem, WordType.GodanVerb, []),
    ('ん', 'ぶ', WordType.DaDeStem, WordType.GodanVerb, []),
    ('ん', 'む', WordType.DaDeStem, WordType.GodanVerb, []),
    ('ん', '', WordType.Initial, WordType.IrrealisStem, [Reason.Negative]),
]


def get_deinflect_rule_groups():
    """
    Get deinflection rule groups, organized by length.
    
    Returns:
        List of rule groups, each containing rules of the same length
    """
    rule_groups = []
    prev_len = -1
    current_group = None
    
    for from_ending, to_replacement, from_type, to_type, reasons in DEINFLECT_RULE_DATA:
        from_len = len(from_ending)
        
        if prev_len != from_len:
            prev_len = from_len
            current_group = {
                'rules': [],
                'fromLen': from_len
            }
            rule_groups.append(current_group)
        
        current_group['rules'].append({
            'from': from_ending,
            'to': to_replacement,
            'fromType': from_type,
            'toType': to_type,
            'reasons': reasons
        })
    
    return rule_groups

