# Generated by Snowball 2.0.0 - https://snowballstem.org/

from .basestemmer import BaseStemmer
from .among import Among


class HungarianStemmer(BaseStemmer):
    '''
    This class implements the stemming algorithm defined by a snowball script.
    Generated by Snowball 2.0.0 - https://snowballstem.org/
    '''

    a_0 = [
        Among(u"cs", -1, -1),
        Among(u"dzs", -1, -1),
        Among(u"gy", -1, -1),
        Among(u"ly", -1, -1),
        Among(u"ny", -1, -1),
        Among(u"sz", -1, -1),
        Among(u"ty", -1, -1),
        Among(u"zs", -1, -1)
    ]

    a_1 = [
        Among(u"\u00E1", -1, 1),
        Among(u"\u00E9", -1, 2)
    ]

    a_2 = [
        Among(u"bb", -1, -1),
        Among(u"cc", -1, -1),
        Among(u"dd", -1, -1),
        Among(u"ff", -1, -1),
        Among(u"gg", -1, -1),
        Among(u"jj", -1, -1),
        Among(u"kk", -1, -1),
        Among(u"ll", -1, -1),
        Among(u"mm", -1, -1),
        Among(u"nn", -1, -1),
        Among(u"pp", -1, -1),
        Among(u"rr", -1, -1),
        Among(u"ccs", -1, -1),
        Among(u"ss", -1, -1),
        Among(u"zzs", -1, -1),
        Among(u"tt", -1, -1),
        Among(u"vv", -1, -1),
        Among(u"ggy", -1, -1),
        Among(u"lly", -1, -1),
        Among(u"nny", -1, -1),
        Among(u"tty", -1, -1),
        Among(u"ssz", -1, -1),
        Among(u"zz", -1, -1)
    ]

    a_3 = [
        Among(u"al", -1, 1),
        Among(u"el", -1, 1)
    ]

    a_4 = [
        Among(u"ba", -1, -1),
        Among(u"ra", -1, -1),
        Among(u"be", -1, -1),
        Among(u"re", -1, -1),
        Among(u"ig", -1, -1),
        Among(u"nak", -1, -1),
        Among(u"nek", -1, -1),
        Among(u"val", -1, -1),
        Among(u"vel", -1, -1),
        Among(u"ul", -1, -1),
        Among(u"n\u00E1l", -1, -1),
        Among(u"n\u00E9l", -1, -1),
        Among(u"b\u00F3l", -1, -1),
        Among(u"r\u00F3l", -1, -1),
        Among(u"t\u00F3l", -1, -1),
        Among(u"\u00FCl", -1, -1),
        Among(u"b\u0151l", -1, -1),
        Among(u"r\u0151l", -1, -1),
        Among(u"t\u0151l", -1, -1),
        Among(u"n", -1, -1),
        Among(u"an", 19, -1),
        Among(u"ban", 20, -1),
        Among(u"en", 19, -1),
        Among(u"ben", 22, -1),
        Among(u"k\u00E9ppen", 22, -1),
        Among(u"on", 19, -1),
        Among(u"\u00F6n", 19, -1),
        Among(u"k\u00E9pp", -1, -1),
        Among(u"kor", -1, -1),
        Among(u"t", -1, -1),
        Among(u"at", 29, -1),
        Among(u"et", 29, -1),
        Among(u"k\u00E9nt", 29, -1),
        Among(u"ank\u00E9nt", 32, -1),
        Among(u"enk\u00E9nt", 32, -1),
        Among(u"onk\u00E9nt", 32, -1),
        Among(u"ot", 29, -1),
        Among(u"\u00E9rt", 29, -1),
        Among(u"\u00F6t", 29, -1),
        Among(u"hez", -1, -1),
        Among(u"hoz", -1, -1),
        Among(u"h\u00F6z", -1, -1),
        Among(u"v\u00E1", -1, -1),
        Among(u"v\u00E9", -1, -1)
    ]

    a_5 = [
        Among(u"\u00E1n", -1, 2),
        Among(u"\u00E9n", -1, 1),
        Among(u"\u00E1nk\u00E9nt", -1, 2)
    ]

    a_6 = [
        Among(u"stul", -1, 1),
        Among(u"astul", 0, 1),
        Among(u"\u00E1stul", 0, 2),
        Among(u"st\u00FCl", -1, 1),
        Among(u"est\u00FCl", 3, 1),
        Among(u"\u00E9st\u00FCl", 3, 3)
    ]

    a_7 = [
        Among(u"\u00E1", -1, 1),
        Among(u"\u00E9", -1, 1)
    ]

    a_8 = [
        Among(u"k", -1, 3),
        Among(u"ak", 0, 3),
        Among(u"ek", 0, 3),
        Among(u"ok", 0, 3),
        Among(u"\u00E1k", 0, 1),
        Among(u"\u00E9k", 0, 2),
        Among(u"\u00F6k", 0, 3)
    ]

    a_9 = [
        Among(u"\u00E9i", -1, 1),
        Among(u"\u00E1\u00E9i", 0, 3),
        Among(u"\u00E9\u00E9i", 0, 2),
        Among(u"\u00E9", -1, 1),
        Among(u"k\u00E9", 3, 1),
        Among(u"ak\u00E9", 4, 1),
        Among(u"ek\u00E9", 4, 1),
        Among(u"ok\u00E9", 4, 1),
        Among(u"\u00E1k\u00E9", 4, 3),
        Among(u"\u00E9k\u00E9", 4, 2),
        Among(u"\u00F6k\u00E9", 4, 1),
        Among(u"\u00E9\u00E9", 3, 2)
    ]

    a_10 = [
        Among(u"a", -1, 1),
        Among(u"ja", 0, 1),
        Among(u"d", -1, 1),
        Among(u"ad", 2, 1),
        Among(u"ed", 2, 1),
        Among(u"od", 2, 1),
        Among(u"\u00E1d", 2, 2),
        Among(u"\u00E9d", 2, 3),
        Among(u"\u00F6d", 2, 1),
        Among(u"e", -1, 1),
        Among(u"je", 9, 1),
        Among(u"nk", -1, 1),
        Among(u"unk", 11, 1),
        Among(u"\u00E1nk", 11, 2),
        Among(u"\u00E9nk", 11, 3),
        Among(u"\u00FCnk", 11, 1),
        Among(u"uk", -1, 1),
        Among(u"juk", 16, 1),
        Among(u"\u00E1juk", 17, 2),
        Among(u"\u00FCk", -1, 1),
        Among(u"j\u00FCk", 19, 1),
        Among(u"\u00E9j\u00FCk", 20, 3),
        Among(u"m", -1, 1),
        Among(u"am", 22, 1),
        Among(u"em", 22, 1),
        Among(u"om", 22, 1),
        Among(u"\u00E1m", 22, 2),
        Among(u"\u00E9m", 22, 3),
        Among(u"o", -1, 1),
        Among(u"\u00E1", -1, 2),
        Among(u"\u00E9", -1, 3)
    ]

    a_11 = [
        Among(u"id", -1, 1),
        Among(u"aid", 0, 1),
        Among(u"jaid", 1, 1),
        Among(u"eid", 0, 1),
        Among(u"jeid", 3, 1),
        Among(u"\u00E1id", 0, 2),
        Among(u"\u00E9id", 0, 3),
        Among(u"i", -1, 1),
        Among(u"ai", 7, 1),
        Among(u"jai", 8, 1),
        Among(u"ei", 7, 1),
        Among(u"jei", 10, 1),
        Among(u"\u00E1i", 7, 2),
        Among(u"\u00E9i", 7, 3),
        Among(u"itek", -1, 1),
        Among(u"eitek", 14, 1),
        Among(u"jeitek", 15, 1),
        Among(u"\u00E9itek", 14, 3),
        Among(u"ik", -1, 1),
        Among(u"aik", 18, 1),
        Among(u"jaik", 19, 1),
        Among(u"eik", 18, 1),
        Among(u"jeik", 21, 1),
        Among(u"\u00E1ik", 18, 2),
        Among(u"\u00E9ik", 18, 3),
        Among(u"ink", -1, 1),
        Among(u"aink", 25, 1),
        Among(u"jaink", 26, 1),
        Among(u"eink", 25, 1),
        Among(u"jeink", 28, 1),
        Among(u"\u00E1ink", 25, 2),
        Among(u"\u00E9ink", 25, 3),
        Among(u"aitok", -1, 1),
        Among(u"jaitok", 32, 1),
        Among(u"\u00E1itok", -1, 2),
        Among(u"im", -1, 1),
        Among(u"aim", 35, 1),
        Among(u"jaim", 36, 1),
        Among(u"eim", 35, 1),
        Among(u"jeim", 38, 1),
        Among(u"\u00E1im", 35, 2),
        Among(u"\u00E9im", 35, 3)
    ]

    g_v = [17, 65, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 17, 36, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1]

    I_p1 = 0

    def __r_mark_regions(self):
        # (, line 44
        self.I_p1 = self.limit
        # or, line 51
        try:
            v_1 = self.cursor
            try:
                # (, line 48
                if not self.in_grouping(HungarianStemmer.g_v, 97, 369):
                    raise lab1()
                # goto non v, line 48
                if not self.go_in_grouping(HungarianStemmer.g_v, 97, 369):
                    raise lab1()
                # or, line 49
                try:
                    v_2 = self.cursor
                    try:
                        # among, line 49
                        if self.find_among(HungarianStemmer.a_0) == 0:
                            raise lab3()
                        raise lab2()
                    except lab3: pass
                    self.cursor = v_2
                    # next, line 49
                    if self.cursor >= self.limit:
                        raise lab1()
                    self.cursor += 1
                except lab2: pass
                # setmark p1, line 50
                self.I_p1 = self.cursor
                raise lab0()
            except lab1: pass
            self.cursor = v_1
            # (, line 53
            if not self.out_grouping(HungarianStemmer.g_v, 97, 369):
                return False
            # gopast grouping v, line 53
            if not self.go_out_grouping(HungarianStemmer.g_v, 97, 369):
                return False
            self.cursor += 1
            # setmark p1, line 53
            self.I_p1 = self.cursor
        except lab0: pass
        return True

    def __r_R1(self):
        if not self.I_p1 <= self.cursor:
            return False
        return True

    def __r_v_ending(self):
        # (, line 60
        # [, line 61
        self.ket = self.cursor
        # substring, line 61
        among_var = self.find_among_b(HungarianStemmer.a_1)
        if among_var == 0:
            return False
        # ], line 61
        self.bra = self.cursor
        # call R1, line 61
        if not self.__r_R1():
            return False
        if among_var == 1:
            # (, line 62
            # <-, line 62
            if not self.slice_from(u"a"):
                return False
        elif among_var == 2:
            # (, line 63
            # <-, line 63
            if not self.slice_from(u"e"):
                return False
        return True

    def __r_double(self):
        # (, line 67
        # test, line 68
        v_1 = self.limit - self.cursor
        # among, line 68
        if self.find_among_b(HungarianStemmer.a_2) == 0:
            return False
        self.cursor = self.limit - v_1
        return True

    def __r_undouble(self):
        # (, line 72
        # next, line 73
        if self.cursor <= self.limit_backward:
            return False
        self.cursor -= 1
        # [, line 73
        self.ket = self.cursor
        # hop, line 73
        c = self.cursor - 1
        if self.limit_backward > c or c > self.limit:
            return False
        self.cursor = c
        # ], line 73
        self.bra = self.cursor
        # delete, line 73
        if not self.slice_del():
            return False

        return True

    def __r_instrum(self):
        # (, line 76
        # [, line 77
        self.ket = self.cursor
        # substring, line 77
        if self.find_among_b(HungarianStemmer.a_3) == 0:
            return False
        # ], line 77
        self.bra = self.cursor
        # call R1, line 77
        if not self.__r_R1():
            return False
        # (, line 78
        # call double, line 78
        if not self.__r_double():
            return False
        # delete, line 81
        if not self.slice_del():
            return False

        # call undouble, line 82
        if not self.__r_undouble():
            return False
        return True

    def __r_case(self):
        # (, line 86
        # [, line 87
        self.ket = self.cursor
        # substring, line 87
        if self.find_among_b(HungarianStemmer.a_4) == 0:
            return False
        # ], line 87
        self.bra = self.cursor
        # call R1, line 87
        if not self.__r_R1():
            return False
        # delete, line 111
        if not self.slice_del():
            return False

        # call v_ending, line 112
        if not self.__r_v_ending():
            return False
        return True

    def __r_case_special(self):
        # (, line 115
        # [, line 116
        self.ket = self.cursor
        # substring, line 116
        among_var = self.find_among_b(HungarianStemmer.a_5)
        if among_var == 0:
            return False
        # ], line 116
        self.bra = self.cursor
        # call R1, line 116
        if not self.__r_R1():
            return False
        if among_var == 1:
            # (, line 117
            # <-, line 117
            if not self.slice_from(u"e"):
                return False
        elif among_var == 2:
            # (, line 118
            # <-, line 118
            if not self.slice_from(u"a"):
                return False
        return True

    def __r_case_other(self):
        # (, line 123
        # [, line 124
        self.ket = self.cursor
        # substring, line 124
        among_var = self.find_among_b(HungarianStemmer.a_6)
        if among_var == 0:
            return False
        # ], line 124
        self.bra = self.cursor
        # call R1, line 124
        if not self.__r_R1():
            return False
        if among_var == 1:
            # (, line 125
            # delete, line 125
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 127
            # <-, line 127
            if not self.slice_from(u"a"):
                return False
        elif among_var == 3:
            # (, line 128
            # <-, line 128
            if not self.slice_from(u"e"):
                return False
        return True

    def __r_factive(self):
        # (, line 132
        # [, line 133
        self.ket = self.cursor
        # substring, line 133
        if self.find_among_b(HungarianStemmer.a_7) == 0:
            return False
        # ], line 133
        self.bra = self.cursor
        # call R1, line 133
        if not self.__r_R1():
            return False
        # (, line 134
        # call double, line 134
        if not self.__r_double():
            return False
        # delete, line 137
        if not self.slice_del():
            return False

        # call undouble, line 138
        if not self.__r_undouble():
            return False
        return True

    def __r_plural(self):
        # (, line 141
        # [, line 142
        self.ket = self.cursor
        # substring, line 142
        among_var = self.find_among_b(HungarianStemmer.a_8)
        if among_var == 0:
            return False
        # ], line 142
        self.bra = self.cursor
        # call R1, line 142
        if not self.__r_R1():
            return False
        if among_var == 1:
            # (, line 143
            # <-, line 143
            if not self.slice_from(u"a"):
                return False
        elif among_var == 2:
            # (, line 144
            # <-, line 144
            if not self.slice_from(u"e"):
                return False
        elif among_var == 3:
            # (, line 145
            # delete, line 145
            if not self.slice_del():
                return False

        return True

    def __r_owned(self):
        # (, line 153
        # [, line 154
        self.ket = self.cursor
        # substring, line 154
        among_var = self.find_among_b(HungarianStemmer.a_9)
        if among_var == 0:
            return False
        # ], line 154
        self.bra = self.cursor
        # call R1, line 154
        if not self.__r_R1():
            return False
        if among_var == 1:
            # (, line 155
            # delete, line 155
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 156
            # <-, line 156
            if not self.slice_from(u"e"):
                return False
        elif among_var == 3:
            # (, line 157
            # <-, line 157
            if not self.slice_from(u"a"):
                return False
        return True

    def __r_sing_owner(self):
        # (, line 167
        # [, line 168
        self.ket = self.cursor
        # substring, line 168
        among_var = self.find_among_b(HungarianStemmer.a_10)
        if among_var == 0:
            return False
        # ], line 168
        self.bra = self.cursor
        # call R1, line 168
        if not self.__r_R1():
            return False
        if among_var == 1:
            # (, line 169
            # delete, line 169
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 170
            # <-, line 170
            if not self.slice_from(u"a"):
                return False
        elif among_var == 3:
            # (, line 171
            # <-, line 171
            if not self.slice_from(u"e"):
                return False
        return True

    def __r_plur_owner(self):
        # (, line 192
        # [, line 193
        self.ket = self.cursor
        # substring, line 193
        among_var = self.find_among_b(HungarianStemmer.a_11)
        if among_var == 0:
            return False
        # ], line 193
        self.bra = self.cursor
        # call R1, line 193
        if not self.__r_R1():
            return False
        if among_var == 1:
            # (, line 194
            # delete, line 194
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 195
            # <-, line 195
            if not self.slice_from(u"a"):
                return False
        elif among_var == 3:
            # (, line 196
            # <-, line 196
            if not self.slice_from(u"e"):
                return False
        return True

    def _stem(self):
        # (, line 228
        # do, line 229
        v_1 = self.cursor
        # call mark_regions, line 229
        self.__r_mark_regions()
        self.cursor = v_1
        # backwards, line 230
        self.limit_backward = self.cursor
        self.cursor = self.limit
        # (, line 230
        # do, line 231
        v_2 = self.limit - self.cursor
        # call instrum, line 231
        self.__r_instrum()
        self.cursor = self.limit - v_2
        # do, line 232
        v_3 = self.limit - self.cursor
        # call case, line 232
        self.__r_case()
        self.cursor = self.limit - v_3
        # do, line 233
        v_4 = self.limit - self.cursor
        # call case_special, line 233
        self.__r_case_special()
        self.cursor = self.limit - v_4
        # do, line 234
        v_5 = self.limit - self.cursor
        # call case_other, line 234
        self.__r_case_other()
        self.cursor = self.limit - v_5
        # do, line 235
        v_6 = self.limit - self.cursor
        # call factive, line 235
        self.__r_factive()
        self.cursor = self.limit - v_6
        # do, line 236
        v_7 = self.limit - self.cursor
        # call owned, line 236
        self.__r_owned()
        self.cursor = self.limit - v_7
        # do, line 237
        v_8 = self.limit - self.cursor
        # call sing_owner, line 237
        self.__r_sing_owner()
        self.cursor = self.limit - v_8
        # do, line 238
        v_9 = self.limit - self.cursor
        # call plur_owner, line 238
        self.__r_plur_owner()
        self.cursor = self.limit - v_9
        # do, line 239
        v_10 = self.limit - self.cursor
        # call plural, line 239
        self.__r_plural()
        self.cursor = self.limit - v_10
        self.cursor = self.limit_backward
        return True


class lab0(BaseException): pass


class lab1(BaseException): pass


class lab2(BaseException): pass


class lab3(BaseException): pass
