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

from .basestemmer import BaseStemmer
from .among import Among


class PortugueseStemmer(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"", -1, 3),
        Among(u"\u00E3", 0, 1),
        Among(u"\u00F5", 0, 2)
    ]

    a_1 = [
        Among(u"", -1, 3),
        Among(u"a~", 0, 1),
        Among(u"o~", 0, 2)
    ]

    a_2 = [
        Among(u"ic", -1, -1),
        Among(u"ad", -1, -1),
        Among(u"os", -1, -1),
        Among(u"iv", -1, 1)
    ]

    a_3 = [
        Among(u"ante", -1, 1),
        Among(u"avel", -1, 1),
        Among(u"\u00EDvel", -1, 1)
    ]

    a_4 = [
        Among(u"ic", -1, 1),
        Among(u"abil", -1, 1),
        Among(u"iv", -1, 1)
    ]

    a_5 = [
        Among(u"ica", -1, 1),
        Among(u"\u00E2ncia", -1, 1),
        Among(u"\u00EAncia", -1, 4),
        Among(u"logia", -1, 2),
        Among(u"ira", -1, 9),
        Among(u"adora", -1, 1),
        Among(u"osa", -1, 1),
        Among(u"ista", -1, 1),
        Among(u"iva", -1, 8),
        Among(u"eza", -1, 1),
        Among(u"idade", -1, 7),
        Among(u"ante", -1, 1),
        Among(u"mente", -1, 6),
        Among(u"amente", 12, 5),
        Among(u"\u00E1vel", -1, 1),
        Among(u"\u00EDvel", -1, 1),
        Among(u"ico", -1, 1),
        Among(u"ismo", -1, 1),
        Among(u"oso", -1, 1),
        Among(u"amento", -1, 1),
        Among(u"imento", -1, 1),
        Among(u"ivo", -1, 8),
        Among(u"a\u00E7a~o", -1, 1),
        Among(u"u\u00E7a~o", -1, 3),
        Among(u"ador", -1, 1),
        Among(u"icas", -1, 1),
        Among(u"\u00EAncias", -1, 4),
        Among(u"logias", -1, 2),
        Among(u"iras", -1, 9),
        Among(u"adoras", -1, 1),
        Among(u"osas", -1, 1),
        Among(u"istas", -1, 1),
        Among(u"ivas", -1, 8),
        Among(u"ezas", -1, 1),
        Among(u"idades", -1, 7),
        Among(u"adores", -1, 1),
        Among(u"antes", -1, 1),
        Among(u"a\u00E7o~es", -1, 1),
        Among(u"u\u00E7o~es", -1, 3),
        Among(u"icos", -1, 1),
        Among(u"ismos", -1, 1),
        Among(u"osos", -1, 1),
        Among(u"amentos", -1, 1),
        Among(u"imentos", -1, 1),
        Among(u"ivos", -1, 8)
    ]

    a_6 = [
        Among(u"ada", -1, 1),
        Among(u"ida", -1, 1),
        Among(u"ia", -1, 1),
        Among(u"aria", 2, 1),
        Among(u"eria", 2, 1),
        Among(u"iria", 2, 1),
        Among(u"ara", -1, 1),
        Among(u"era", -1, 1),
        Among(u"ira", -1, 1),
        Among(u"ava", -1, 1),
        Among(u"asse", -1, 1),
        Among(u"esse", -1, 1),
        Among(u"isse", -1, 1),
        Among(u"aste", -1, 1),
        Among(u"este", -1, 1),
        Among(u"iste", -1, 1),
        Among(u"ei", -1, 1),
        Among(u"arei", 16, 1),
        Among(u"erei", 16, 1),
        Among(u"irei", 16, 1),
        Among(u"am", -1, 1),
        Among(u"iam", 20, 1),
        Among(u"ariam", 21, 1),
        Among(u"eriam", 21, 1),
        Among(u"iriam", 21, 1),
        Among(u"aram", 20, 1),
        Among(u"eram", 20, 1),
        Among(u"iram", 20, 1),
        Among(u"avam", 20, 1),
        Among(u"em", -1, 1),
        Among(u"arem", 29, 1),
        Among(u"erem", 29, 1),
        Among(u"irem", 29, 1),
        Among(u"assem", 29, 1),
        Among(u"essem", 29, 1),
        Among(u"issem", 29, 1),
        Among(u"ado", -1, 1),
        Among(u"ido", -1, 1),
        Among(u"ando", -1, 1),
        Among(u"endo", -1, 1),
        Among(u"indo", -1, 1),
        Among(u"ara~o", -1, 1),
        Among(u"era~o", -1, 1),
        Among(u"ira~o", -1, 1),
        Among(u"ar", -1, 1),
        Among(u"er", -1, 1),
        Among(u"ir", -1, 1),
        Among(u"as", -1, 1),
        Among(u"adas", 47, 1),
        Among(u"idas", 47, 1),
        Among(u"ias", 47, 1),
        Among(u"arias", 50, 1),
        Among(u"erias", 50, 1),
        Among(u"irias", 50, 1),
        Among(u"aras", 47, 1),
        Among(u"eras", 47, 1),
        Among(u"iras", 47, 1),
        Among(u"avas", 47, 1),
        Among(u"es", -1, 1),
        Among(u"ardes", 58, 1),
        Among(u"erdes", 58, 1),
        Among(u"irdes", 58, 1),
        Among(u"ares", 58, 1),
        Among(u"eres", 58, 1),
        Among(u"ires", 58, 1),
        Among(u"asses", 58, 1),
        Among(u"esses", 58, 1),
        Among(u"isses", 58, 1),
        Among(u"astes", 58, 1),
        Among(u"estes", 58, 1),
        Among(u"istes", 58, 1),
        Among(u"is", -1, 1),
        Among(u"ais", 71, 1),
        Among(u"eis", 71, 1),
        Among(u"areis", 73, 1),
        Among(u"ereis", 73, 1),
        Among(u"ireis", 73, 1),
        Among(u"\u00E1reis", 73, 1),
        Among(u"\u00E9reis", 73, 1),
        Among(u"\u00EDreis", 73, 1),
        Among(u"\u00E1sseis", 73, 1),
        Among(u"\u00E9sseis", 73, 1),
        Among(u"\u00EDsseis", 73, 1),
        Among(u"\u00E1veis", 73, 1),
        Among(u"\u00EDeis", 73, 1),
        Among(u"ar\u00EDeis", 84, 1),
        Among(u"er\u00EDeis", 84, 1),
        Among(u"ir\u00EDeis", 84, 1),
        Among(u"ados", -1, 1),
        Among(u"idos", -1, 1),
        Among(u"amos", -1, 1),
        Among(u"\u00E1ramos", 90, 1),
        Among(u"\u00E9ramos", 90, 1),
        Among(u"\u00EDramos", 90, 1),
        Among(u"\u00E1vamos", 90, 1),
        Among(u"\u00EDamos", 90, 1),
        Among(u"ar\u00EDamos", 95, 1),
        Among(u"er\u00EDamos", 95, 1),
        Among(u"ir\u00EDamos", 95, 1),
        Among(u"emos", -1, 1),
        Among(u"aremos", 99, 1),
        Among(u"eremos", 99, 1),
        Among(u"iremos", 99, 1),
        Among(u"\u00E1ssemos", 99, 1),
        Among(u"\u00EAssemos", 99, 1),
        Among(u"\u00EDssemos", 99, 1),
        Among(u"imos", -1, 1),
        Among(u"armos", -1, 1),
        Among(u"ermos", -1, 1),
        Among(u"irmos", -1, 1),
        Among(u"\u00E1mos", -1, 1),
        Among(u"ar\u00E1s", -1, 1),
        Among(u"er\u00E1s", -1, 1),
        Among(u"ir\u00E1s", -1, 1),
        Among(u"eu", -1, 1),
        Among(u"iu", -1, 1),
        Among(u"ou", -1, 1),
        Among(u"ar\u00E1", -1, 1),
        Among(u"er\u00E1", -1, 1),
        Among(u"ir\u00E1", -1, 1)
    ]

    a_7 = [
        Among(u"a", -1, 1),
        Among(u"i", -1, 1),
        Among(u"o", -1, 1),
        Among(u"os", -1, 1),
        Among(u"\u00E1", -1, 1),
        Among(u"\u00ED", -1, 1),
        Among(u"\u00F3", -1, 1)
    ]

    a_8 = [
        Among(u"e", -1, 1),
        Among(u"\u00E7", -1, 2),
        Among(u"\u00E9", -1, 1),
        Among(u"\u00EA", -1, 1)
    ]

    g_v = [17, 65, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 19, 12, 2]

    I_p2 = 0
    I_p1 = 0
    I_pV = 0

    def __r_prelude(self):
        # repeat, line 36
        while True:
            v_1 = self.cursor
            try:
                # (, line 36
                # [, line 37
                self.bra = self.cursor
                # substring, line 37
                among_var = self.find_among(PortugueseStemmer.a_0)
                if among_var == 0:
                    raise lab0()
                # ], line 37
                self.ket = self.cursor
                if among_var == 1:
                    # (, line 38
                    # <-, line 38
                    if not self.slice_from(u"a~"):
                        return False
                elif among_var == 2:
                    # (, line 39
                    # <-, line 39
                    if not self.slice_from(u"o~"):
                        return False
                elif among_var == 3:
                    # (, line 40
                    # next, line 40
                    if self.cursor >= self.limit:
                        raise lab0()
                    self.cursor += 1
                continue
            except lab0: pass
            self.cursor = v_1
            break
        return True

    def __r_mark_regions(self):
        # (, line 44
        self.I_pV = self.limit
        self.I_p1 = self.limit
        self.I_p2 = self.limit
        # do, line 50
        v_1 = self.cursor
        try:
            # (, line 50
            # or, line 52
            try:
                v_2 = self.cursor
                try:
                    # (, line 51
                    if not self.in_grouping(PortugueseStemmer.g_v, 97, 250):
                        raise lab2()
                    # or, line 51
                    try:
                        v_3 = self.cursor
                        try:
                            # (, line 51
                            if not self.out_grouping(PortugueseStemmer.g_v, 97, 250):
                                raise lab4()
                            # gopast grouping v, line 51
                            if not self.go_out_grouping(PortugueseStemmer.g_v, 97, 250):
                                raise lab4()
                            self.cursor += 1
                            raise lab3()
                        except lab4: pass
                        self.cursor = v_3
                        # (, line 51
                        if not self.in_grouping(PortugueseStemmer.g_v, 97, 250):
                            raise lab2()
                        # gopast non v, line 51
                        if not self.go_in_grouping(PortugueseStemmer.g_v, 97, 250):
                            raise lab2()
                        self.cursor += 1
                    except lab3: pass
                    raise lab1()
                except lab2: pass
                self.cursor = v_2
                # (, line 53
                if not self.out_grouping(PortugueseStemmer.g_v, 97, 250):
                    raise lab0()
                # or, line 53
                try:
                    v_4 = self.cursor
                    try:
                        # (, line 53
                        if not self.out_grouping(PortugueseStemmer.g_v, 97, 250):
                            raise lab6()
                        # gopast grouping v, line 53
                        if not self.go_out_grouping(PortugueseStemmer.g_v, 97, 250):
                            raise lab6()
                        self.cursor += 1
                        raise lab5()
                    except lab6: pass
                    self.cursor = v_4
                    # (, line 53
                    if not self.in_grouping(PortugueseStemmer.g_v, 97, 250):
                        raise lab0()
                    # next, line 53
                    if self.cursor >= self.limit:
                        raise lab0()
                    self.cursor += 1
                except lab5: pass
            except lab1: pass
            # setmark pV, line 54
            self.I_pV = self.cursor
        except lab0: pass
        self.cursor = v_1
        # do, line 56
        v_5 = self.cursor
        try:
            # (, line 56
            # gopast grouping v, line 57
            if not self.go_out_grouping(PortugueseStemmer.g_v, 97, 250):
                raise lab7()
            self.cursor += 1
            # gopast non v, line 57
            if not self.go_in_grouping(PortugueseStemmer.g_v, 97, 250):
                raise lab7()
            self.cursor += 1
            # setmark p1, line 57
            self.I_p1 = self.cursor
            # gopast grouping v, line 58
            if not self.go_out_grouping(PortugueseStemmer.g_v, 97, 250):
                raise lab7()
            self.cursor += 1
            # gopast non v, line 58
            if not self.go_in_grouping(PortugueseStemmer.g_v, 97, 250):
                raise lab7()
            self.cursor += 1
            # setmark p2, line 58
            self.I_p2 = self.cursor
        except lab7: pass
        self.cursor = v_5
        return True

    def __r_postlude(self):
        # repeat, line 62
        while True:
            v_1 = self.cursor
            try:
                # (, line 62
                # [, line 63
                self.bra = self.cursor
                # substring, line 63
                among_var = self.find_among(PortugueseStemmer.a_1)
                if among_var == 0:
                    raise lab0()
                # ], line 63
                self.ket = self.cursor
                if among_var == 1:
                    # (, line 64
                    # <-, line 64
                    if not self.slice_from(u"\u00E3"):
                        return False
                elif among_var == 2:
                    # (, line 65
                    # <-, line 65
                    if not self.slice_from(u"\u00F5"):
                        return False
                elif among_var == 3:
                    # (, line 66
                    # next, line 66
                    if self.cursor >= self.limit:
                        raise lab0()
                    self.cursor += 1
                continue
            except lab0: pass
            self.cursor = v_1
            break
        return True

    def __r_RV(self):
        if not self.I_pV <= self.cursor:
            return False
        return True

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

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

    def __r_standard_suffix(self):
        # (, line 76
        # [, line 77
        self.ket = self.cursor
        # substring, line 77
        among_var = self.find_among_b(PortugueseStemmer.a_5)
        if among_var == 0:
            return False
        # ], line 77
        self.bra = self.cursor
        if among_var == 1:
            # (, line 92
            # call R2, line 93
            if not self.__r_R2():
                return False
            # delete, line 93
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 97
            # call R2, line 98
            if not self.__r_R2():
                return False
            # <-, line 98
            if not self.slice_from(u"log"):
                return False
        elif among_var == 3:
            # (, line 101
            # call R2, line 102
            if not self.__r_R2():
                return False
            # <-, line 102
            if not self.slice_from(u"u"):
                return False
        elif among_var == 4:
            # (, line 105
            # call R2, line 106
            if not self.__r_R2():
                return False
            # <-, line 106
            if not self.slice_from(u"ente"):
                return False
        elif among_var == 5:
            # (, line 109
            # call R1, line 110
            if not self.__r_R1():
                return False
            # delete, line 110
            if not self.slice_del():
                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(PortugueseStemmer.a_2)
                if among_var == 0:
                    self.cursor = self.limit - v_1
                    raise lab0()
                # ], line 112
                self.bra = self.cursor
                # call R2, line 112
                if not self.__r_R2():
                    self.cursor = self.limit - v_1
                    raise lab0()
                # delete, line 112
                if not self.slice_del():
                    return False

                if among_var == 1:
                    # (, line 113
                    # [, line 113
                    self.ket = self.cursor
                    # literal, line 113
                    if not self.eq_s_b(u"at"):
                        self.cursor = self.limit - v_1
                        raise lab0()
                    # ], line 113
                    self.bra = self.cursor
                    # call R2, line 113
                    if not self.__r_R2():
                        self.cursor = self.limit - v_1
                        raise lab0()
                    # delete, line 113
                    if not self.slice_del():
                        return False

            except lab0: pass
        elif among_var == 6:
            # (, line 121
            # call R2, line 122
            if not self.__r_R2():
                return False
            # delete, line 122
            if not self.slice_del():
                return False

            # try, line 123
            v_2 = self.limit - self.cursor
            try:
                # (, line 123
                # [, line 124
                self.ket = self.cursor
                # substring, line 124
                if self.find_among_b(PortugueseStemmer.a_3) == 0:
                    self.cursor = self.limit - v_2
                    raise lab1()
                # ], line 124
                self.bra = self.cursor
                # (, line 127
                # call R2, line 127
                if not self.__r_R2():
                    self.cursor = self.limit - v_2
                    raise lab1()
                # delete, line 127
                if not self.slice_del():
                    return False

            except lab1: pass
        elif among_var == 7:
            # (, line 133
            # call R2, line 134
            if not self.__r_R2():
                return False
            # delete, line 134
            if not self.slice_del():
                return False

            # try, line 135
            v_3 = self.limit - self.cursor
            try:
                # (, line 135
                # [, line 136
                self.ket = self.cursor
                # substring, line 136
                if self.find_among_b(PortugueseStemmer.a_4) == 0:
                    self.cursor = self.limit - v_3
                    raise lab2()
                # ], line 136
                self.bra = self.cursor
                # (, line 139
                # call R2, line 139
                if not self.__r_R2():
                    self.cursor = self.limit - v_3
                    raise lab2()
                # delete, line 139
                if not self.slice_del():
                    return False

            except lab2: pass
        elif among_var == 8:
            # (, line 145
            # call R2, line 146
            if not self.__r_R2():
                return False
            # delete, line 146
            if not self.slice_del():
                return False

            # try, line 147
            v_4 = self.limit - self.cursor
            try:
                # (, line 147
                # [, line 148
                self.ket = self.cursor
                # literal, line 148
                if not self.eq_s_b(u"at"):
                    self.cursor = self.limit - v_4
                    raise lab3()
                # ], line 148
                self.bra = self.cursor
                # call R2, line 148
                if not self.__r_R2():
                    self.cursor = self.limit - v_4
                    raise lab3()
                # delete, line 148
                if not self.slice_del():
                    return False

            except lab3: pass
        elif among_var == 9:
            # (, line 152
            # call RV, line 153
            if not self.__r_RV():
                return False
            # literal, line 153
            if not self.eq_s_b(u"e"):
                return False
            # <-, line 154
            if not self.slice_from(u"ir"):
                return False
        return True

    def __r_verb_suffix(self):
        # setlimit, line 159
        if self.cursor < self.I_pV:
            return False
        v_2 = self.limit_backward
        self.limit_backward = self.I_pV
        # (, line 159
        # [, line 160
        self.ket = self.cursor
        # substring, line 160
        if self.find_among_b(PortugueseStemmer.a_6) == 0:
            self.limit_backward = v_2
            return False
        # ], line 160
        self.bra = self.cursor
        # (, line 179
        # delete, line 179
        if not self.slice_del():
            return False

        self.limit_backward = v_2
        return True

    def __r_residual_suffix(self):
        # (, line 183
        # [, line 184
        self.ket = self.cursor
        # substring, line 184
        if self.find_among_b(PortugueseStemmer.a_7) == 0:
            return False
        # ], line 184
        self.bra = self.cursor
        # (, line 187
        # call RV, line 187
        if not self.__r_RV():
            return False
        # delete, line 187
        if not self.slice_del():
            return False

        return True

    def __r_residual_form(self):
        # (, line 191
        # [, line 192
        self.ket = self.cursor
        # substring, line 192
        among_var = self.find_among_b(PortugueseStemmer.a_8)
        if among_var == 0:
            return False
        # ], line 192
        self.bra = self.cursor
        if among_var == 1:
            # (, line 194
            # call RV, line 194
            if not self.__r_RV():
                return False
            # delete, line 194
            if not self.slice_del():
                return False

            # [, line 194
            self.ket = self.cursor
            # or, line 194
            try:
                v_1 = self.limit - self.cursor
                try:
                    # (, line 194
                    # literal, line 194
                    if not self.eq_s_b(u"u"):
                        raise lab1()
                    # ], line 194
                    self.bra = self.cursor
                    # test, line 194
                    v_2 = self.limit - self.cursor
                    # literal, line 194
                    if not self.eq_s_b(u"g"):
                        raise lab1()
                    self.cursor = self.limit - v_2
                    raise lab0()
                except lab1: pass
                self.cursor = self.limit - v_1
                # (, line 195
                # literal, line 195
                if not self.eq_s_b(u"i"):
                    return False
                # ], line 195
                self.bra = self.cursor
                # test, line 195
                v_3 = self.limit - self.cursor
                # literal, line 195
                if not self.eq_s_b(u"c"):
                    return False
                self.cursor = self.limit - v_3
            except lab0: pass
            # call RV, line 195
            if not self.__r_RV():
                return False
            # delete, line 195
            if not self.slice_del():
                return False

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

    def _stem(self):
        # (, line 201
        # do, line 202
        v_1 = self.cursor
        # call prelude, line 202
        self.__r_prelude()
        self.cursor = v_1
        # do, line 203
        # call mark_regions, line 203
        self.__r_mark_regions()
        # backwards, line 204
        self.limit_backward = self.cursor
        self.cursor = self.limit
        # (, line 204
        # do, line 205
        v_3 = self.limit - self.cursor
        try:
            # (, line 205
            # or, line 209
            try:
                v_4 = self.limit - self.cursor
                try:
                    # (, line 206
                    # and, line 207
                    v_5 = self.limit - self.cursor
                    # (, line 206
                    # or, line 206
                    try:
                        v_6 = self.limit - self.cursor
                        try:
                            # call standard_suffix, line 206
                            if not self.__r_standard_suffix():
                                raise lab4()
                            raise lab3()
                        except lab4: pass
                        self.cursor = self.limit - v_6
                        # call verb_suffix, line 206
                        if not self.__r_verb_suffix():
                            raise lab2()
                    except lab3: pass
                    self.cursor = self.limit - v_5
                    # do, line 207
                    v_7 = self.limit - self.cursor
                    try:
                        # (, line 207
                        # [, line 207
                        self.ket = self.cursor
                        # literal, line 207
                        if not self.eq_s_b(u"i"):
                            raise lab5()
                        # ], line 207
                        self.bra = self.cursor
                        # test, line 207
                        v_8 = self.limit - self.cursor
                        # literal, line 207
                        if not self.eq_s_b(u"c"):
                            raise lab5()
                        self.cursor = self.limit - v_8
                        # call RV, line 207
                        if not self.__r_RV():
                            raise lab5()
                        # delete, line 207
                        if not self.slice_del():
                            return False

                    except lab5: pass
                    self.cursor = self.limit - v_7
                    raise lab1()
                except lab2: pass
                self.cursor = self.limit - v_4
                # call residual_suffix, line 209
                if not self.__r_residual_suffix():
                    raise lab0()
            except lab1: pass
        except lab0: pass
        self.cursor = self.limit - v_3
        # do, line 211
        v_9 = self.limit - self.cursor
        # call residual_form, line 211
        self.__r_residual_form()
        self.cursor = self.limit - v_9
        self.cursor = self.limit_backward
        # do, line 213
        v_10 = self.cursor
        # call postlude, line 213
        self.__r_postlude()
        self.cursor = v_10
        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
