# Generated from basque.sbl by Snowball 3.1.1 - https://snowballstem.org/

from .basestemmer import BaseStemmer
from .among import Among


class BasqueStemmer(BaseStemmer):
    '''
    This class implements the stemming algorithm defined by a snowball script.
    Generated from basque.sbl by Snowball 3.1.1 - https://snowballstem.org/
    '''

    g_v = {"a", "e", "i", "o", "u"}

    I_p2 = 0
    I_p1 = 0
    I_pV = 0

    def __r_mark_regions(self):
        self.I_pV = self.limit
        self.I_p1 = self.limit
        self.I_p2 = self.limit
        v_1 = self.cursor
        try:
            while True:
                v_2 = self.cursor
                try:
                    if not self.in_grouping(BasqueStemmer.g_v):
                        raise lab1()
                    while True:
                        v_3 = self.cursor
                        try:
                            if not self.out_grouping(BasqueStemmer.g_v):
                                raise lab2()
                            if not self.go_out_grouping(BasqueStemmer.g_v):
                                raise lab2()
                            self.cursor += 1
                            break
                        except lab2: pass
                        self.cursor = v_3
                        if not self.in_grouping(BasqueStemmer.g_v):
                            raise lab1()
                        if not self.go_in_grouping(BasqueStemmer.g_v):
                            raise lab1()
                        self.cursor += 1
                        break
                    break
                except lab1: pass
                self.cursor = v_2
                if not self.out_grouping(BasqueStemmer.g_v):
                    raise lab0()
                while True:
                    v_4 = self.cursor
                    try:
                        if not self.out_grouping(BasqueStemmer.g_v):
                            raise lab1()
                        if not self.go_out_grouping(BasqueStemmer.g_v):
                            raise lab1()
                        self.cursor += 1
                        break
                    except lab1: pass
                    self.cursor = v_4
                    if not self.in_grouping(BasqueStemmer.g_v):
                        raise lab0()
                    if self.cursor >= self.limit:
                        raise lab0()
                    self.cursor += 1
                    break
                break
            self.I_pV = self.cursor
        except lab0: pass
        self.cursor = v_1
        v_5 = self.cursor
        try:
            if not self.go_out_grouping(BasqueStemmer.g_v):
                raise lab0()
            self.cursor += 1
            if not self.go_in_grouping(BasqueStemmer.g_v):
                raise lab0()
            self.cursor += 1
            self.I_p1 = self.cursor
            if not self.go_out_grouping(BasqueStemmer.g_v):
                raise lab0()
            self.cursor += 1
            if not self.go_in_grouping(BasqueStemmer.g_v):
                raise lab0()
            self.cursor += 1
            self.I_p2 = self.cursor
        except lab0: pass
        self.cursor = v_5
        return True

    def __r_RV(self):
        return self.I_pV <= self.cursor

    def __r_R2(self):
        return self.I_p2 <= self.cursor

    def __r_aditzak(self):
        self.ket = self.cursor
        among_var = self.find_among_b(BasqueStemmer.a_0)
        if among_var == 0:
            return False
        self.bra = self.cursor
        if among_var == 1:
            if not self.__r_RV():
                return False
            self.slice_del()
        elif among_var == 2:
            if not self.__r_R2():
                return False
            self.slice_del()
        return True

    def __r_izenak(self):
        self.ket = self.cursor
        among_var = self.find_among_b(BasqueStemmer.a_1)
        if among_var == 0:
            return False
        self.bra = self.cursor
        if among_var == 1:
            if not self.__r_RV():
                return False
            self.slice_del()
        elif among_var == 2:
            if not self.__r_R2():
                return False
            self.slice_del()
        elif among_var == 3:
            self.slice_from("jok")
        elif among_var == 4:
            if self.I_p1 > self.cursor:
                return False
            self.slice_del()
        elif among_var == 5:
            self.slice_from("tra")
        elif among_var == 6:
            self.slice_from("minutu")
        return True

    def __r_adjetiboak(self):
        self.ket = self.cursor
        among_var = self.find_among_b(BasqueStemmer.a_2)
        if among_var == 0:
            return False
        self.bra = self.cursor
        if among_var == 1:
            if not self.__r_RV():
                return False
            self.slice_del()
        else:
            self.slice_from("z")
        return True

    def _stem(self):
        self.__r_mark_regions()
        self.limit_backward = self.cursor
        self.cursor = self.limit
        while True:
            v_1 = self.limit - self.cursor
            try:
                if not self.__r_aditzak():
                    raise lab0()
                continue
            except lab0: pass
            self.cursor = self.limit - v_1
            break
        while True:
            v_2 = self.limit - self.cursor
            try:
                if not self.__r_izenak():
                    raise lab0()
                continue
            except lab0: pass
            self.cursor = self.limit - v_2
            break
        v_3 = self.limit - self.cursor
        self.__r_adjetiboak()
        self.cursor = self.limit - v_3
        self.cursor = self.limit_backward
        return True

    a_0 = [
        Among("idea", -1, 1),
        Among("bidea", 0, 1),
        Among("kidea", 0, 1),
        Among("pidea", 0, 1),
        Among("kundea", -1, 1),
        Among("galea", -1, 1),
        Among("tailea", -1, 1),
        Among("tzailea", -1, 1),
        Among("gunea", -1, 1),
        Among("kunea", -1, 1),
        Among("tzaga", -1, 1),
        Among("gaia", -1, 1),
        Among("aldia", -1, 1),
        Among("taldia", 12, 1),
        Among("karia", -1, 1),
        Among("garria", -1, 2),
        Among("karria", -1, 1),
        Among("ka", -1, 1),
        Among("tzaka", 17, 1),
        Among("la", -1, 1),
        Among("mena", -1, 1),
        Among("pena", -1, 1),
        Among("kina", -1, 1),
        Among("ezina", -1, 1),
        Among("tezina", 23, 1),
        Among("kuna", -1, 1),
        Among("tuna", -1, 1),
        Among("kizuna", -1, 1),
        Among("era", -1, 1),
        Among("bera", 28, 1),
        Among("arabera", 29, -1),
        Among("kera", 28, 1),
        Among("pera", 28, 1),
        Among("orra", -1, 1),
        Among("korra", 33, 1),
        Among("dura", -1, 1),
        Among("gura", -1, 1),
        Among("kura", -1, 1),
        Among("tura", -1, 1),
        Among("eta", -1, 1),
        Among("keta", 39, 1),
        Among("gailua", -1, 1),
        Among("eza", -1, 1),
        Among("erreza", 42, 1),
        Among("tza", -1, 2),
        Among("gaitza", 44, 1),
        Among("kaitza", 44, 1),
        Among("kuntza", 44, 1),
        Among("ide", -1, 1),
        Among("bide", 48, 1),
        Among("kide", 48, 1),
        Among("pide", 48, 1),
        Among("kunde", -1, 1),
        Among("tzake", -1, 1),
        Among("tzeke", -1, 1),
        Among("le", -1, 1),
        Among("gale", 55, 1),
        Among("taile", 55, 1),
        Among("tzaile", 55, 1),
        Among("gune", -1, 1),
        Among("kune", -1, 1),
        Among("tze", -1, 1),
        Among("atze", 61, 1),
        Among("gai", -1, 1),
        Among("aldi", -1, 1),
        Among("taldi", 64, 1),
        Among("ki", -1, 1),
        Among("ari", -1, 1),
        Among("kari", 67, 1),
        Among("lari", 67, 1),
        Among("tari", 67, 1),
        Among("etari", 70, 1),
        Among("garri", -1, 2),
        Among("karri", -1, 1),
        Among("arazi", -1, 1),
        Among("tarazi", 74, 1),
        Among("an", -1, 1),
        Among("ean", 76, 1),
        Among("rean", 77, 1),
        Among("kan", 76, 1),
        Among("etan", 76, 1),
        Among("atseden", -1, -1),
        Among("men", -1, 1),
        Among("pen", -1, 1),
        Among("kin", -1, 1),
        Among("rekin", 84, 1),
        Among("ezin", -1, 1),
        Among("tezin", 86, 1),
        Among("tun", -1, 1),
        Among("kizun", -1, 1),
        Among("go", -1, 1),
        Among("ago", 90, 1),
        Among("tio", -1, 1),
        Among("dako", -1, 1),
        Among("or", -1, 1),
        Among("kor", 94, 1),
        Among("tzat", -1, 1),
        Among("du", -1, 1),
        Among("gailu", -1, 1),
        Among("tu", -1, 1),
        Among("atu", 99, 1),
        Among("aldatu", 100, 1),
        Among("tatu", 100, 1),
        Among("baditu", 99, -1),
        Among("ez", -1, 1),
        Among("errez", 104, 1),
        Among("tzez", 104, 1),
        Among("gaitz", -1, 1),
        Among("kaitz", -1, 1)
    ]

    a_1 = [
        Among("ada", -1, 1),
        Among("kada", 0, 1),
        Among("anda", -1, 1),
        Among("denda", -1, 1),
        Among("gabea", -1, 1),
        Among("kabea", -1, 1),
        Among("aldea", -1, 1),
        Among("kaldea", 6, 1),
        Among("taldea", 6, 1),
        Among("ordea", -1, 1),
        Among("zalea", -1, 1),
        Among("tzalea", 10, 1),
        Among("gilea", -1, 1),
        Among("emea", -1, 1),
        Among("kumea", -1, 1),
        Among("nea", -1, 1),
        Among("enea", 15, 1),
        Among("zionea", 15, 1),
        Among("unea", 15, 1),
        Among("gunea", 18, 1),
        Among("pea", -1, 1),
        Among("aurrea", -1, 1),
        Among("tea", -1, 1),
        Among("kotea", 22, 1),
        Among("artea", 22, 1),
        Among("ostea", 22, 1),
        Among("etxea", -1, 1),
        Among("ga", -1, 1),
        Among("anga", 27, 1),
        Among("gaia", -1, 1),
        Among("aldia", -1, 1),
        Among("taldia", 30, 1),
        Among("handia", -1, 1),
        Among("mendia", -1, 1),
        Among("geia", -1, 1),
        Among("egia", -1, 1),
        Among("degia", 35, 1),
        Among("tegia", 35, 1),
        Among("nahia", -1, 1),
        Among("ohia", -1, 1),
        Among("kia", -1, 1),
        Among("tokia", 40, 1),
        Among("oia", -1, 1),
        Among("koia", 42, 1),
        Among("aria", -1, 1),
        Among("karia", 44, 1),
        Among("laria", 44, 1),
        Among("taria", 44, 1),
        Among("eria", -1, 1),
        Among("keria", 48, 1),
        Among("teria", 48, 1),
        Among("garria", -1, 2),
        Among("larria", -1, 1),
        Among("kirria", -1, 1),
        Among("duria", -1, 1),
        Among("asia", -1, 1),
        Among("tia", -1, 1),
        Among("ezia", -1, 1),
        Among("bizia", -1, 1),
        Among("ontzia", -1, 1),
        Among("ka", -1, 1),
        Among("joka", 60, 3),
        Among("aurka", 60, -1),
        Among("ska", 60, 1),
        Among("xka", 60, 1),
        Among("zka", 60, 1),
        Among("gibela", -1, 1),
        Among("gela", -1, 1),
        Among("kaila", -1, 1),
        Among("skila", -1, 1),
        Among("tila", -1, 1),
        Among("ola", -1, 1),
        Among("na", -1, 1),
        Among("kana", 72, 1),
        Among("ena", 72, 1),
        Among("garrena", 74, 1),
        Among("gerrena", 74, 1),
        Among("urrena", 74, 1),
        Among("zaina", 72, 1),
        Among("tzaina", 78, 1),
        Among("kina", 72, 1),
        Among("mina", 72, 1),
        Among("garna", 72, 1),
        Among("una", 72, 1),
        Among("duna", 83, 1),
        Among("asuna", 83, 1),
        Among("tasuna", 85, 1),
        Among("ondoa", -1, 1),
        Among("kondoa", 87, 1),
        Among("ngoa", -1, 1),
        Among("zioa", -1, 1),
        Among("koa", -1, 1),
        Among("takoa", 91, 1),
        Among("zkoa", 91, 1),
        Among("noa", -1, 1),
        Among("zinoa", 94, 1),
        Among("aroa", -1, 1),
        Among("taroa", 96, 1),
        Among("zaroa", 96, 1),
        Among("eroa", -1, 1),
        Among("oroa", -1, 1),
        Among("osoa", -1, 1),
        Among("toa", -1, 1),
        Among("ttoa", 102, 1),
        Among("ztoa", 102, 1),
        Among("txoa", -1, 1),
        Among("tzoa", -1, 1),
        Among("ñoa", -1, 1),
        Among("ra", -1, 1),
        Among("ara", 108, 1),
        Among("dara", 109, 1),
        Among("liara", 109, 1),
        Among("tiara", 109, 1),
        Among("tara", 109, 1),
        Among("etara", 113, 1),
        Among("tzara", 109, 1),
        Among("bera", 108, 1),
        Among("kera", 108, 1),
        Among("pera", 108, 1),
        Among("ora", 108, 2),
        Among("tzarra", 108, 1),
        Among("korra", 108, 1),
        Among("tra", 108, 1),
        Among("sa", -1, 1),
        Among("osa", 123, 1),
        Among("ta", -1, 1),
        Among("eta", 125, 1),
        Among("keta", 126, 1),
        Among("sta", 125, 1),
        Among("dua", -1, 1),
        Among("mendua", 129, 1),
        Among("ordua", 129, 1),
        Among("lekua", -1, 1),
        Among("burua", -1, 1),
        Among("durua", -1, 1),
        Among("tsua", -1, 1),
        Among("tua", -1, 1),
        Among("mentua", 136, 1),
        Among("estua", 136, 1),
        Among("txua", -1, 1),
        Among("zua", -1, 1),
        Among("tzua", 140, 1),
        Among("za", -1, 1),
        Among("eza", 142, 1),
        Among("eroza", 142, 1),
        Among("tza", 142, 2),
        Among("koitza", 145, 1),
        Among("antza", 145, 1),
        Among("gintza", 145, 1),
        Among("kintza", 145, 1),
        Among("kuntza", 145, 1),
        Among("gabe", -1, 1),
        Among("kabe", -1, 1),
        Among("kide", -1, 1),
        Among("alde", -1, 1),
        Among("kalde", 154, 1),
        Among("talde", 154, 1),
        Among("orde", -1, 1),
        Among("ge", -1, 1),
        Among("zale", -1, 1),
        Among("tzale", 159, 1),
        Among("gile", -1, 1),
        Among("eme", -1, 1),
        Among("kume", -1, 1),
        Among("ne", -1, 1),
        Among("zione", 164, 1),
        Among("une", 164, 1),
        Among("gune", 166, 1),
        Among("pe", -1, 1),
        Among("aurre", -1, 1),
        Among("te", -1, 1),
        Among("kote", 170, 1),
        Among("arte", 170, 1),
        Among("oste", 170, 1),
        Among("etxe", -1, 1),
        Among("gai", -1, 1),
        Among("di", -1, 1),
        Among("aldi", 176, 1),
        Among("taldi", 177, 1),
        Among("geldi", 176, -1),
        Among("handi", 176, 1),
        Among("mendi", 176, 1),
        Among("gei", -1, 1),
        Among("egi", -1, 1),
        Among("degi", 183, 1),
        Among("tegi", 183, 1),
        Among("nahi", -1, 1),
        Among("ohi", -1, 1),
        Among("ki", -1, 1),
        Among("toki", 188, 1),
        Among("oi", -1, 1),
        Among("goi", 190, 1),
        Among("koi", 190, 1),
        Among("ari", -1, 1),
        Among("kari", 193, 1),
        Among("lari", 193, 1),
        Among("tari", 193, 1),
        Among("garri", -1, 2),
        Among("larri", -1, 1),
        Among("kirri", -1, 1),
        Among("duri", -1, 1),
        Among("asi", -1, 1),
        Among("ti", -1, 1),
        Among("ontzi", -1, 1),
        Among("ñi", -1, 1),
        Among("ak", -1, 1),
        Among("ek", -1, 1),
        Among("tarik", -1, 1),
        Among("gibel", -1, 1),
        Among("ail", -1, 1),
        Among("kail", 209, 1),
        Among("kan", -1, 1),
        Among("tan", -1, 1),
        Among("etan", 212, 1),
        Among("en", -1, 4),
        Among("ren", 214, 2),
        Among("garren", 215, 1),
        Among("gerren", 215, 1),
        Among("urren", 215, 1),
        Among("ten", 214, 4),
        Among("tzen", 214, 4),
        Among("zain", -1, 1),
        Among("tzain", 221, 1),
        Among("kin", -1, 1),
        Among("min", -1, 1),
        Among("dun", -1, 1),
        Among("asun", -1, 1),
        Among("tasun", 226, 1),
        Among("aizun", -1, 1),
        Among("ondo", -1, 1),
        Among("kondo", 229, 1),
        Among("go", -1, 1),
        Among("ngo", 231, 1),
        Among("zio", -1, 1),
        Among("ko", -1, 1),
        Among("trako", 234, 5),
        Among("tako", 234, 1),
        Among("etako", 236, 1),
        Among("eko", 234, 1),
        Among("tariko", 234, 1),
        Among("sko", 234, 1),
        Among("tuko", 234, 1),
        Among("minutuko", 241, 6),
        Among("zko", 234, 1),
        Among("no", -1, 1),
        Among("zino", 244, 1),
        Among("ro", -1, 1),
        Among("aro", 246, 1),
        Among("igaro", 247, -1),
        Among("taro", 247, 1),
        Among("zaro", 247, 1),
        Among("ero", 246, 1),
        Among("giro", 246, 1),
        Among("oro", 246, 1),
        Among("oso", -1, 1),
        Among("to", -1, 1),
        Among("tto", 255, 1),
        Among("zto", 255, 1),
        Among("txo", -1, 1),
        Among("tzo", -1, 1),
        Among("gintzo", 259, 1),
        Among("ño", -1, 1),
        Among("zp", -1, 1),
        Among("ar", -1, 1),
        Among("dar", 263, 1),
        Among("behar", 263, 1),
        Among("zehar", 263, -1),
        Among("liar", 263, 1),
        Among("tiar", 263, 1),
        Among("tar", 263, 1),
        Among("tzar", 263, 1),
        Among("or", -1, 2),
        Among("kor", 271, 1),
        Among("os", -1, 1),
        Among("ket", -1, 1),
        Among("du", -1, 1),
        Among("mendu", 275, 1),
        Among("ordu", 275, 1),
        Among("leku", -1, 1),
        Among("buru", -1, 2),
        Among("duru", -1, 1),
        Among("tsu", -1, 1),
        Among("tu", -1, 1),
        Among("tatu", 282, 4),
        Among("mentu", 282, 1),
        Among("estu", 282, 1),
        Among("txu", -1, 1),
        Among("zu", -1, 1),
        Among("tzu", 287, 1),
        Among("gintzu", 288, 1),
        Among("z", -1, 1),
        Among("ez", 290, 1),
        Among("eroz", 290, 1),
        Among("tz", 290, 1),
        Among("koitz", 293, 1)
    ]

    a_2 = [
        Among("zlea", -1, 2),
        Among("keria", -1, 1),
        Among("la", -1, 1),
        Among("era", -1, 1),
        Among("dade", -1, 1),
        Among("tade", -1, 1),
        Among("date", -1, 1),
        Among("tate", -1, 1),
        Among("gi", -1, 1),
        Among("ki", -1, 1),
        Among("ik", -1, 1),
        Among("lanik", 10, 1),
        Among("rik", 10, 1),
        Among("larik", 12, 1),
        Among("ztik", 10, 1),
        Among("go", -1, 1),
        Among("ro", -1, 1),
        Among("ero", 16, 1),
        Among("to", -1, 1)
    ]


class lab0(BaseException): pass


class lab1(BaseException): pass


class lab2(BaseException): pass
