# This file was generated automatically by the Snowball to Python compiler
# http://snowballstem.org/

from .basestemmer import BaseStemmer
from .among import Among


class RussianStemmer(BaseStemmer):
    '''
    This class was automatically generated by a Snowball to Python compiler
    It implements the stemming algorithm defined by a snowball script.
    '''

    a_0 = [
        Among(u"\u0432", -1, 1),
        Among(u"\u0438\u0432", 0, 2),
        Among(u"\u044B\u0432", 0, 2),
        Among(u"\u0432\u0448\u0438", -1, 1),
        Among(u"\u0438\u0432\u0448\u0438", 3, 2),
        Among(u"\u044B\u0432\u0448\u0438", 3, 2),
        Among(u"\u0432\u0448\u0438\u0441\u044C", -1, 1),
        Among(u"\u0438\u0432\u0448\u0438\u0441\u044C", 6, 2),
        Among(u"\u044B\u0432\u0448\u0438\u0441\u044C", 6, 2)
    ]

    a_1 = [
        Among(u"\u0435\u0435", -1, 1),
        Among(u"\u0438\u0435", -1, 1),
        Among(u"\u043E\u0435", -1, 1),
        Among(u"\u044B\u0435", -1, 1),
        Among(u"\u0438\u043C\u0438", -1, 1),
        Among(u"\u044B\u043C\u0438", -1, 1),
        Among(u"\u0435\u0439", -1, 1),
        Among(u"\u0438\u0439", -1, 1),
        Among(u"\u043E\u0439", -1, 1),
        Among(u"\u044B\u0439", -1, 1),
        Among(u"\u0435\u043C", -1, 1),
        Among(u"\u0438\u043C", -1, 1),
        Among(u"\u043E\u043C", -1, 1),
        Among(u"\u044B\u043C", -1, 1),
        Among(u"\u0435\u0433\u043E", -1, 1),
        Among(u"\u043E\u0433\u043E", -1, 1),
        Among(u"\u0435\u043C\u0443", -1, 1),
        Among(u"\u043E\u043C\u0443", -1, 1),
        Among(u"\u0438\u0445", -1, 1),
        Among(u"\u044B\u0445", -1, 1),
        Among(u"\u0435\u044E", -1, 1),
        Among(u"\u043E\u044E", -1, 1),
        Among(u"\u0443\u044E", -1, 1),
        Among(u"\u044E\u044E", -1, 1),
        Among(u"\u0430\u044F", -1, 1),
        Among(u"\u044F\u044F", -1, 1)
    ]

    a_2 = [
        Among(u"\u0435\u043C", -1, 1),
        Among(u"\u043D\u043D", -1, 1),
        Among(u"\u0432\u0448", -1, 1),
        Among(u"\u0438\u0432\u0448", 2, 2),
        Among(u"\u044B\u0432\u0448", 2, 2),
        Among(u"\u0449", -1, 1),
        Among(u"\u044E\u0449", 5, 1),
        Among(u"\u0443\u044E\u0449", 6, 2)
    ]

    a_3 = [
        Among(u"\u0441\u044C", -1, 1),
        Among(u"\u0441\u044F", -1, 1)
    ]

    a_4 = [
        Among(u"\u043B\u0430", -1, 1),
        Among(u"\u0438\u043B\u0430", 0, 2),
        Among(u"\u044B\u043B\u0430", 0, 2),
        Among(u"\u043D\u0430", -1, 1),
        Among(u"\u0435\u043D\u0430", 3, 2),
        Among(u"\u0435\u0442\u0435", -1, 1),
        Among(u"\u0438\u0442\u0435", -1, 2),
        Among(u"\u0439\u0442\u0435", -1, 1),
        Among(u"\u0435\u0439\u0442\u0435", 7, 2),
        Among(u"\u0443\u0439\u0442\u0435", 7, 2),
        Among(u"\u043B\u0438", -1, 1),
        Among(u"\u0438\u043B\u0438", 10, 2),
        Among(u"\u044B\u043B\u0438", 10, 2),
        Among(u"\u0439", -1, 1),
        Among(u"\u0435\u0439", 13, 2),
        Among(u"\u0443\u0439", 13, 2),
        Among(u"\u043B", -1, 1),
        Among(u"\u0438\u043B", 16, 2),
        Among(u"\u044B\u043B", 16, 2),
        Among(u"\u0435\u043C", -1, 1),
        Among(u"\u0438\u043C", -1, 2),
        Among(u"\u044B\u043C", -1, 2),
        Among(u"\u043D", -1, 1),
        Among(u"\u0435\u043D", 22, 2),
        Among(u"\u043B\u043E", -1, 1),
        Among(u"\u0438\u043B\u043E", 24, 2),
        Among(u"\u044B\u043B\u043E", 24, 2),
        Among(u"\u043D\u043E", -1, 1),
        Among(u"\u0435\u043D\u043E", 27, 2),
        Among(u"\u043D\u043D\u043E", 27, 1),
        Among(u"\u0435\u0442", -1, 1),
        Among(u"\u0443\u0435\u0442", 30, 2),
        Among(u"\u0438\u0442", -1, 2),
        Among(u"\u044B\u0442", -1, 2),
        Among(u"\u044E\u0442", -1, 1),
        Among(u"\u0443\u044E\u0442", 34, 2),
        Among(u"\u044F\u0442", -1, 2),
        Among(u"\u043D\u044B", -1, 1),
        Among(u"\u0435\u043D\u044B", 37, 2),
        Among(u"\u0442\u044C", -1, 1),
        Among(u"\u0438\u0442\u044C", 39, 2),
        Among(u"\u044B\u0442\u044C", 39, 2),
        Among(u"\u0435\u0448\u044C", -1, 1),
        Among(u"\u0438\u0448\u044C", -1, 2),
        Among(u"\u044E", -1, 2),
        Among(u"\u0443\u044E", 44, 2)
    ]

    a_5 = [
        Among(u"\u0430", -1, 1),
        Among(u"\u0435\u0432", -1, 1),
        Among(u"\u043E\u0432", -1, 1),
        Among(u"\u0435", -1, 1),
        Among(u"\u0438\u0435", 3, 1),
        Among(u"\u044C\u0435", 3, 1),
        Among(u"\u0438", -1, 1),
        Among(u"\u0435\u0438", 6, 1),
        Among(u"\u0438\u0438", 6, 1),
        Among(u"\u0430\u043C\u0438", 6, 1),
        Among(u"\u044F\u043C\u0438", 6, 1),
        Among(u"\u0438\u044F\u043C\u0438", 10, 1),
        Among(u"\u0439", -1, 1),
        Among(u"\u0435\u0439", 12, 1),
        Among(u"\u0438\u0435\u0439", 13, 1),
        Among(u"\u0438\u0439", 12, 1),
        Among(u"\u043E\u0439", 12, 1),
        Among(u"\u0430\u043C", -1, 1),
        Among(u"\u0435\u043C", -1, 1),
        Among(u"\u0438\u0435\u043C", 18, 1),
        Among(u"\u043E\u043C", -1, 1),
        Among(u"\u044F\u043C", -1, 1),
        Among(u"\u0438\u044F\u043C", 21, 1),
        Among(u"\u043E", -1, 1),
        Among(u"\u0443", -1, 1),
        Among(u"\u0430\u0445", -1, 1),
        Among(u"\u044F\u0445", -1, 1),
        Among(u"\u0438\u044F\u0445", 26, 1),
        Among(u"\u044B", -1, 1),
        Among(u"\u044C", -1, 1),
        Among(u"\u044E", -1, 1),
        Among(u"\u0438\u044E", 30, 1),
        Among(u"\u044C\u044E", 30, 1),
        Among(u"\u044F", -1, 1),
        Among(u"\u0438\u044F", 33, 1),
        Among(u"\u044C\u044F", 33, 1)
    ]

    a_6 = [
        Among(u"\u043E\u0441\u0442", -1, 1),
        Among(u"\u043E\u0441\u0442\u044C", -1, 1)
    ]

    a_7 = [
        Among(u"\u0435\u0439\u0448\u0435", -1, 1),
        Among(u"\u043D", -1, 2),
        Among(u"\u0435\u0439\u0448", -1, 1),
        Among(u"\u044C", -1, 3)
    ]

    g_v = [33, 65, 8, 232]

    I_p2 = 0
    I_pV = 0


    def __r_mark_regions(self):
        # (, line 59
        self.I_pV = self.limit
        self.I_p2 = self.limit
        # do, line 63
        v_1 = self.cursor
        try:
            # (, line 63
            # gopast, line 64
            try:
                while True:
                    try:
                        if not self.in_grouping(RussianStemmer.g_v, 1072, 1103):
                            raise lab2()
                        raise lab1()
                    except lab2: pass
                    if self.cursor >= self.limit:
                        raise lab0()
                    self.cursor += 1
            except lab1: pass
            # setmark pV, line 64
            self.I_pV = self.cursor
            # gopast, line 64
            try:
                while True:
                    try:
                        if not self.out_grouping(RussianStemmer.g_v, 1072, 1103):
                            raise lab4()
                        raise lab3()
                    except lab4: pass
                    if self.cursor >= self.limit:
                        raise lab0()
                    self.cursor += 1
            except lab3: pass
            # gopast, line 65
            try:
                while True:
                    try:
                        if not self.in_grouping(RussianStemmer.g_v, 1072, 1103):
                            raise lab6()
                        raise lab5()
                    except lab6: pass
                    if self.cursor >= self.limit:
                        raise lab0()
                    self.cursor += 1
            except lab5: pass
            # gopast, line 65
            try:
                while True:
                    try:
                        if not self.out_grouping(RussianStemmer.g_v, 1072, 1103):
                            raise lab8()
                        raise lab7()
                    except lab8: pass
                    if self.cursor >= self.limit:
                        raise lab0()
                    self.cursor += 1
            except lab7: pass
            # setmark p2, line 65
            self.I_p2 = self.cursor
        except lab0: pass
        self.cursor = v_1
        return True

    def __r_R2(self):
        if not self.I_p2 <= self.cursor:
            return False
        return True

    def __r_perfective_gerund(self):
        # (, line 73
        # [, line 74
        self.ket = self.cursor
        # substring, line 74
        among_var = self.find_among_b(RussianStemmer.a_0)
        if among_var == 0:
            return False
        # ], line 74
        self.bra = self.cursor
        if among_var == 1:
            # (, line 78
            # or, line 78
            try:
                v_1 = self.limit - self.cursor
                try:
                    # literal, line 78
                    if not self.eq_s_b(u"\u0430"):
                        raise lab1()
                    raise lab0()
                except lab1: pass
                self.cursor = self.limit - v_1
                # literal, line 78
                if not self.eq_s_b(u"\u044F"):
                    return False
            except lab0: pass
            # delete, line 78
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 85
            # delete, line 85
            if not self.slice_del():
                return False

        return True

    def __r_adjective(self):
        # (, line 89
        # [, line 90
        self.ket = self.cursor
        # substring, line 90
        if self.find_among_b(RussianStemmer.a_1) == 0:
            return False
        # ], line 90
        self.bra = self.cursor
        # (, line 99
        # delete, line 99
        if not self.slice_del():
            return False

        return True

    def __r_adjectival(self):
        # (, line 103
        # call adjective, line 104
        if not self.__r_adjective():
            return False
        # try, line 111
        v_1 = self.limit - self.cursor
        try:
            # (, line 111
            # [, line 112
            self.ket = self.cursor
            # substring, line 112
            among_var = self.find_among_b(RussianStemmer.a_2)
            if among_var == 0:
                self.cursor = self.limit - v_1
                raise lab0()
            # ], line 112
            self.bra = self.cursor
            if among_var == 1:
                # (, line 117
                # or, line 117
                try:
                    v_2 = self.limit - self.cursor
                    try:
                        # literal, line 117
                        if not self.eq_s_b(u"\u0430"):
                            raise lab2()
                        raise lab1()
                    except lab2: pass
                    self.cursor = self.limit - v_2
                    # literal, line 117
                    if not self.eq_s_b(u"\u044F"):
                        self.cursor = self.limit - v_1
                        raise lab0()
                except lab1: pass
                # delete, line 117
                if not self.slice_del():
                    return False

            elif among_var == 2:
                # (, line 124
                # delete, line 124
                if not self.slice_del():
                    return False

        except lab0: pass
        return True

    def __r_reflexive(self):
        # (, line 130
        # [, line 131
        self.ket = self.cursor
        # substring, line 131
        if self.find_among_b(RussianStemmer.a_3) == 0:
            return False
        # ], line 131
        self.bra = self.cursor
        # (, line 134
        # delete, line 134
        if not self.slice_del():
            return False

        return True

    def __r_verb(self):
        # (, line 138
        # [, line 139
        self.ket = self.cursor
        # substring, line 139
        among_var = self.find_among_b(RussianStemmer.a_4)
        if among_var == 0:
            return False
        # ], line 139
        self.bra = self.cursor
        if among_var == 1:
            # (, line 145
            # or, line 145
            try:
                v_1 = self.limit - self.cursor
                try:
                    # literal, line 145
                    if not self.eq_s_b(u"\u0430"):
                        raise lab1()
                    raise lab0()
                except lab1: pass
                self.cursor = self.limit - v_1
                # literal, line 145
                if not self.eq_s_b(u"\u044F"):
                    return False
            except lab0: pass
            # delete, line 145
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 153
            # delete, line 153
            if not self.slice_del():
                return False

        return True

    def __r_noun(self):
        # (, line 161
        # [, line 162
        self.ket = self.cursor
        # substring, line 162
        if self.find_among_b(RussianStemmer.a_5) == 0:
            return False
        # ], line 162
        self.bra = self.cursor
        # (, line 169
        # delete, line 169
        if not self.slice_del():
            return False

        return True

    def __r_derivational(self):
        # (, line 177
        # [, line 178
        self.ket = self.cursor
        # substring, line 178
        if self.find_among_b(RussianStemmer.a_6) == 0:
            return False
        # ], line 178
        self.bra = self.cursor
        # call R2, line 178
        if not self.__r_R2():
            return False
        # (, line 181
        # delete, line 181
        if not self.slice_del():
            return False

        return True

    def __r_tidy_up(self):
        # (, line 185
        # [, line 186
        self.ket = self.cursor
        # substring, line 186
        among_var = self.find_among_b(RussianStemmer.a_7)
        if among_var == 0:
            return False
        # ], line 186
        self.bra = self.cursor
        if among_var == 1:
            # (, line 190
            # delete, line 190
            if not self.slice_del():
                return False

            # [, line 191
            self.ket = self.cursor
            # literal, line 191
            if not self.eq_s_b(u"\u043D"):
                return False
            # ], line 191
            self.bra = self.cursor
            # literal, line 191
            if not self.eq_s_b(u"\u043D"):
                return False
            # delete, line 191
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 194
            # literal, line 194
            if not self.eq_s_b(u"\u043D"):
                return False
            # delete, line 194
            if not self.slice_del():
                return False

        elif among_var == 3:
            # (, line 196
            # delete, line 196
            if not self.slice_del():
                return False

        return True

    def _stem(self):
        # (, line 201
        # do, line 205
        v_1 = self.cursor
        try:
            # repeat, line 205
            try:
                while True:
                    try:
                        v_2 = self.cursor
                        try:
                            # (, line 205
                            # goto, line 205
                            try:
                                while True:
                                    v_3 = self.cursor
                                    try:
                                        # (, line 205
                                        # [, line 205
                                        self.bra = self.cursor
                                        # literal, line 205
                                        if not self.eq_s(u"\u0451"):
                                            raise lab5()
                                        # ], line 205
                                        self.ket = self.cursor
                                        self.cursor = v_3
                                        raise lab4()
                                    except lab5: pass
                                    self.cursor = v_3
                                    if self.cursor >= self.limit:
                                        raise lab3()
                                    self.cursor += 1
                            except lab4: pass
                            # <-, line 205
                            if not self.slice_from(u"\u0435"):
                                return False
                            raise lab2()
                        except lab3: pass
                        self.cursor = v_2
                        raise lab1()
                    except lab2: pass
            except lab1: pass
        except lab0: pass
        self.cursor = v_1
        # do, line 207
        # call mark_regions, line 207
        self.__r_mark_regions()
        # backwards, line 208
        self.limit_backward = self.cursor
        self.cursor = self.limit
        # setlimit, line 208
        if self.cursor < self.I_pV:
            return False
        v_6 = self.limit_backward
        self.limit_backward = self.I_pV
        # (, line 208
        # do, line 209
        v_7 = self.limit - self.cursor
        try:
            # (, line 209
            # or, line 210
            try:
                v_8 = self.limit - self.cursor
                try:
                    # call perfective_gerund, line 210
                    if not self.__r_perfective_gerund():
                        raise lab8()
                    raise lab7()
                except lab8: pass
                self.cursor = self.limit - v_8
                # (, line 211
                # try, line 211
                v_9 = self.limit - self.cursor
                try:
                    # call reflexive, line 211
                    if not self.__r_reflexive():
                        self.cursor = self.limit - v_9
                        raise lab9()
                except lab9: pass
                # or, line 212
                try:
                    v_10 = self.limit - self.cursor
                    try:
                        # call adjectival, line 212
                        if not self.__r_adjectival():
                            raise lab11()
                        raise lab10()
                    except lab11: pass
                    self.cursor = self.limit - v_10
                    try:
                        # call verb, line 212
                        if not self.__r_verb():
                            raise lab12()
                        raise lab10()
                    except lab12: pass
                    self.cursor = self.limit - v_10
                    # call noun, line 212
                    if not self.__r_noun():
                        raise lab6()
                except lab10: pass
            except lab7: pass
        except lab6: pass
        self.cursor = self.limit - v_7
        # try, line 215
        v_11 = self.limit - self.cursor
        try:
            # (, line 215
            # [, line 215
            self.ket = self.cursor
            # literal, line 215
            if not self.eq_s_b(u"\u0438"):
                self.cursor = self.limit - v_11
                raise lab13()
            # ], line 215
            self.bra = self.cursor
            # delete, line 215
            if not self.slice_del():
                return False

        except lab13: pass
        # do, line 218
        v_12 = self.limit - self.cursor
        # call derivational, line 218
        self.__r_derivational()
        self.cursor = self.limit - v_12
        # do, line 219
        v_13 = self.limit - self.cursor
        # call tidy_up, line 219
        self.__r_tidy_up()
        self.cursor = self.limit - v_13
        self.limit_backward = v_6
        self.cursor = self.limit_backward
        return True


class lab0(BaseException): pass


class lab1(BaseException): pass


class lab2(BaseException): pass


class lab3(BaseException): pass


class lab4(BaseException): pass


class lab5(BaseException): pass


class lab6(BaseException): pass


class lab7(BaseException): pass


class lab8(BaseException): pass


class lab9(BaseException): pass


class lab10(BaseException): pass


class lab11(BaseException): pass


class lab12(BaseException): pass


class lab13(BaseException): pass
