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

from .basestemmer import BaseStemmer
from .among import Among


class IrishStemmer(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"b'", -1, 1),
        Among(u"bh", -1, 4),
        Among(u"bhf", 1, 2),
        Among(u"bp", -1, 8),
        Among(u"ch", -1, 5),
        Among(u"d'", -1, 1),
        Among(u"d'fh", 5, 2),
        Among(u"dh", -1, 6),
        Among(u"dt", -1, 9),
        Among(u"fh", -1, 2),
        Among(u"gc", -1, 5),
        Among(u"gh", -1, 7),
        Among(u"h-", -1, 1),
        Among(u"m'", -1, 1),
        Among(u"mb", -1, 4),
        Among(u"mh", -1, 10),
        Among(u"n-", -1, 1),
        Among(u"nd", -1, 6),
        Among(u"ng", -1, 7),
        Among(u"ph", -1, 8),
        Among(u"sh", -1, 3),
        Among(u"t-", -1, 1),
        Among(u"th", -1, 9),
        Among(u"ts", -1, 3)
    ]

    a_1 = [
        Among(u"\u00EDochta", -1, 1),
        Among(u"a\u00EDochta", 0, 1),
        Among(u"ire", -1, 2),
        Among(u"aire", 2, 2),
        Among(u"abh", -1, 1),
        Among(u"eabh", 4, 1),
        Among(u"ibh", -1, 1),
        Among(u"aibh", 6, 1),
        Among(u"amh", -1, 1),
        Among(u"eamh", 8, 1),
        Among(u"imh", -1, 1),
        Among(u"aimh", 10, 1),
        Among(u"\u00EDocht", -1, 1),
        Among(u"a\u00EDocht", 12, 1),
        Among(u"ir\u00ED", -1, 2),
        Among(u"air\u00ED", 14, 2)
    ]

    a_2 = [
        Among(u"\u00F3ideacha", -1, 6),
        Among(u"patacha", -1, 5),
        Among(u"achta", -1, 1),
        Among(u"arcachta", 2, 2),
        Among(u"eachta", 2, 1),
        Among(u"grafa\u00EDochta", -1, 4),
        Among(u"paite", -1, 5),
        Among(u"ach", -1, 1),
        Among(u"each", 7, 1),
        Among(u"\u00F3ideach", 8, 6),
        Among(u"gineach", 8, 3),
        Among(u"patach", 7, 5),
        Among(u"grafa\u00EDoch", -1, 4),
        Among(u"pataigh", -1, 5),
        Among(u"\u00F3idigh", -1, 6),
        Among(u"acht\u00FAil", -1, 1),
        Among(u"eacht\u00FAil", 15, 1),
        Among(u"gineas", -1, 3),
        Among(u"ginis", -1, 3),
        Among(u"acht", -1, 1),
        Among(u"arcacht", 19, 2),
        Among(u"eacht", 19, 1),
        Among(u"grafa\u00EDocht", -1, 4),
        Among(u"arcachta\u00ED", -1, 2),
        Among(u"grafa\u00EDochta\u00ED", -1, 4)
    ]

    a_3 = [
        Among(u"imid", -1, 1),
        Among(u"aimid", 0, 1),
        Among(u"\u00EDmid", -1, 1),
        Among(u"a\u00EDmid", 2, 1),
        Among(u"adh", -1, 2),
        Among(u"eadh", 4, 2),
        Among(u"faidh", -1, 1),
        Among(u"fidh", -1, 1),
        Among(u"\u00E1il", -1, 2),
        Among(u"ain", -1, 2),
        Among(u"tear", -1, 2),
        Among(u"tar", -1, 2)
    ]

    g_v = [17, 65, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 17, 4, 2]

    I_p2 = 0
    I_p1 = 0
    I_pV = 0


    def __r_mark_regions(self):
        # (, line 28
        self.I_pV = self.limit
        self.I_p1 = self.limit
        self.I_p2 = self.limit
        # do, line 34
        v_1 = self.cursor
        try:
            # (, line 34
            # gopast, line 35
            try:
                while True:
                    try:
                        if not self.in_grouping(IrishStemmer.g_v, 97, 250):
                            raise lab2()
                        raise lab1()
                    except lab2: pass
                    if self.cursor >= self.limit:
                        raise lab0()
                    self.cursor += 1
            except lab1: pass
            # setmark pV, line 35
            self.I_pV = self.cursor
        except lab0: pass
        self.cursor = v_1
        # do, line 37
        v_3 = self.cursor
        try:
            # (, line 37
            # gopast, line 38
            try:
                while True:
                    try:
                        if not self.in_grouping(IrishStemmer.g_v, 97, 250):
                            raise lab5()
                        raise lab4()
                    except lab5: pass
                    if self.cursor >= self.limit:
                        raise lab3()
                    self.cursor += 1
            except lab4: pass
            # gopast, line 38
            try:
                while True:
                    try:
                        if not self.out_grouping(IrishStemmer.g_v, 97, 250):
                            raise lab7()
                        raise lab6()
                    except lab7: pass
                    if self.cursor >= self.limit:
                        raise lab3()
                    self.cursor += 1
            except lab6: pass
            # setmark p1, line 38
            self.I_p1 = self.cursor
            # gopast, line 39
            try:
                while True:
                    try:
                        if not self.in_grouping(IrishStemmer.g_v, 97, 250):
                            raise lab9()
                        raise lab8()
                    except lab9: pass
                    if self.cursor >= self.limit:
                        raise lab3()
                    self.cursor += 1
            except lab8: pass
            # gopast, line 39
            try:
                while True:
                    try:
                        if not self.out_grouping(IrishStemmer.g_v, 97, 250):
                            raise lab11()
                        raise lab10()
                    except lab11: pass
                    if self.cursor >= self.limit:
                        raise lab3()
                    self.cursor += 1
            except lab10: pass
            # setmark p2, line 39
            self.I_p2 = self.cursor
        except lab3: pass
        self.cursor = v_3
        return True

    def __r_initial_morph(self):
        # (, line 43
        # [, line 44
        self.bra = self.cursor
        # substring, line 44
        among_var = self.find_among(IrishStemmer.a_0)
        if among_var == 0:
            return False
        # ], line 44
        self.ket = self.cursor
        if among_var == 1:
            # (, line 46
            # delete, line 46
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 52
            # <-, line 52
            if not self.slice_from(u"f"):
                return False
        elif among_var == 3:
            # (, line 58
            # <-, line 58
            if not self.slice_from(u"s"):
                return False
        elif among_var == 4:
            # (, line 61
            # <-, line 61
            if not self.slice_from(u"b"):
                return False
        elif among_var == 5:
            # (, line 63
            # <-, line 63
            if not self.slice_from(u"c"):
                return False
        elif among_var == 6:
            # (, line 65
            # <-, line 65
            if not self.slice_from(u"d"):
                return False
        elif among_var == 7:
            # (, line 69
            # <-, line 69
            if not self.slice_from(u"g"):
                return False
        elif among_var == 8:
            # (, line 71
            # <-, line 71
            if not self.slice_from(u"p"):
                return False
        elif among_var == 9:
            # (, line 75
            # <-, line 75
            if not self.slice_from(u"t"):
                return False
        elif among_var == 10:
            # (, line 89
            # <-, line 89
            if not self.slice_from(u"m"):
                return False
        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_noun_sfx(self):
        # (, line 103
        # [, line 104
        self.ket = self.cursor
        # substring, line 104
        among_var = self.find_among_b(IrishStemmer.a_1)
        if among_var == 0:
            return False
        # ], line 104
        self.bra = self.cursor
        if among_var == 1:
            # (, line 108
            # call R1, line 108
            if not self.__r_R1():
                return False
            # delete, line 108
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 110
            # call R2, line 110
            if not self.__r_R2():
                return False
            # delete, line 110
            if not self.slice_del():
                return False

        return True

    def __r_deriv(self):
        # (, line 113
        # [, line 114
        self.ket = self.cursor
        # substring, line 114
        among_var = self.find_among_b(IrishStemmer.a_2)
        if among_var == 0:
            return False
        # ], line 114
        self.bra = self.cursor
        if among_var == 1:
            # (, line 116
            # call R2, line 116
            if not self.__r_R2():
                return False
            # delete, line 116
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 118
            # <-, line 118
            if not self.slice_from(u"arc"):
                return False
        elif among_var == 3:
            # (, line 120
            # <-, line 120
            if not self.slice_from(u"gin"):
                return False
        elif among_var == 4:
            # (, line 122
            # <-, line 122
            if not self.slice_from(u"graf"):
                return False
        elif among_var == 5:
            # (, line 124
            # <-, line 124
            if not self.slice_from(u"paite"):
                return False
        elif among_var == 6:
            # (, line 126
            # <-, line 126
            if not self.slice_from(u"\u00F3id"):
                return False
        return True

    def __r_verb_sfx(self):
        # (, line 129
        # [, line 130
        self.ket = self.cursor
        # substring, line 130
        among_var = self.find_among_b(IrishStemmer.a_3)
        if among_var == 0:
            return False
        # ], line 130
        self.bra = self.cursor
        if among_var == 1:
            # (, line 133
            # call RV, line 133
            if not self.__r_RV():
                return False
            # delete, line 133
            if not self.slice_del():
                return False

        elif among_var == 2:
            # (, line 138
            # call R1, line 138
            if not self.__r_R1():
                return False
            # delete, line 138
            if not self.slice_del():
                return False

        return True

    def _stem(self):
        # (, line 143
        # do, line 144
        v_1 = self.cursor
        # call initial_morph, line 144
        self.__r_initial_morph()
        self.cursor = v_1
        # do, line 145
        # call mark_regions, line 145
        self.__r_mark_regions()
        # backwards, line 146
        self.limit_backward = self.cursor
        self.cursor = self.limit
        # (, line 146
        # do, line 147
        v_3 = self.limit - self.cursor
        # call noun_sfx, line 147
        self.__r_noun_sfx()
        self.cursor = self.limit - v_3
        # do, line 148
        v_4 = self.limit - self.cursor
        # call deriv, line 148
        self.__r_deriv()
        self.cursor = self.limit - v_4
        # do, line 149
        v_5 = self.limit - self.cursor
        # call verb_sfx, line 149
        self.__r_verb_sfx()
        self.cursor = self.limit - v_5
        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
