'Stem a Portuguese word and return the stemmed form.
:param word: The word that is stemmed.
:type word: str or unicode
:return: The stemmed form.
:rtype: unicode'

def stem(self, word):

    word = word.lower()
    if (word in self.stopwords):
        return word
    step1_success = False
    step2_success = False
    word = word.replace(u'\xe3', u'a~').replace(u'\xf5', u'o~').replace(u'q\xfc', u'qu').replace(u'g\xfc', u'gu')
    (r1, r2) = self._r1r2_standard(word, self.__vowels)
    rv = self._rv_standard(word, self.__vowels)
    for suffix in self.__step1_suffixes:
        if word.endswith(suffix):
            if ((suffix == u'amente') and r1.endswith(suffix)):
                step1_success = True
                word = word[:(-6)]
                r2 = r2[:(-6)]
                rv = rv[:(-6)]
                if r2.endswith(u'iv'):
                    word = word[:(-2)]
                    r2 = r2[:(-2)]
                    rv = rv[:(-2)]
                    if r2.endswith(u'at'):
                        word = word[:(-2)]
                        rv = rv[:(-2)]
                elif r2.endswith((u'os', u'ic', u'ad')):
                    word = word[:(-2)]
                    rv = rv[:(-2)]
            elif ((suffix in (u'ira', u'iras')) and rv.endswith(suffix) and (word[((- len(suffix)) - 1):(- len(suffix))] == u'e')):
                step1_success = True
                word = suffix_replace(word, suffix, u'ir')
                rv = suffix_replace(rv, suffix, u'ir')
            elif r2.endswith(suffix):
                step1_success = True
                if (suffix in (u'logia', u'logias')):
                    word = suffix_replace(word, suffix, u'log')
                    rv = suffix_replace(rv, suffix, u'log')
                elif (suffix in (u'u\xe7a~o', u'u\xe7o~es')):
                    word = suffix_replace(word, suffix, u'u')
                    rv = suffix_replace(rv, suffix, u'u')
                elif (suffix in (u'\xeancia', u'\xeancias')):
                    word = suffix_replace(word, suffix, u'ente')
                    rv = suffix_replace(rv, suffix, u'ente')
                elif (suffix == u'mente'):
                    word = word[:(-5)]
                    r2 = r2[:(-5)]
                    rv = rv[:(-5)]
                    if r2.endswith((u'ante', u'avel', u'ivel')):
                        word = word[:(-4)]
                        rv = rv[:(-4)]
                elif (suffix in (u'idade', u'idades')):
                    word = word[:(- len(suffix))]
                    r2 = r2[:(- len(suffix))]
                    rv = rv[:(- len(suffix))]
                    if r2.endswith((u'ic', u'iv')):
                        word = word[:(-2)]
                        rv = rv[:(-2)]
                    elif r2.endswith(u'abil'):
                        word = word[:(-4)]
                        rv = rv[:(-4)]
                elif (suffix in (u'iva', u'ivo', u'ivas', u'ivos')):
                    word = word[:(- len(suffix))]
                    r2 = r2[:(- len(suffix))]
                    rv = rv[:(- len(suffix))]
                    if r2.endswith(u'at'):
                        word = word[:(-2)]
                        rv = rv[:(-2)]
                else:
                    word = word[:(- len(suffix))]
                    rv = rv[:(- len(suffix))]
            break
    if (not step1_success):
        for suffix in self.__step2_suffixes:
            if rv.endswith(suffix):
                step2_success = True
                word = word[:(- len(suffix))]
                rv = rv[:(- len(suffix))]
                break
    if (step1_success or step2_success):
        if (rv.endswith(u'i') and (word[(-2)] == u'c')):
            word = word[:(-1)]
            rv = rv[:(-1)]
    if ((not step1_success) and (not step2_success)):
        for suffix in self.__step4_suffixes:
            if rv.endswith(suffix):
                word = word[:(- len(suffix))]
                rv = rv[:(- len(suffix))]
                break
    if rv.endswith((u'e', u'\xe9', u'\xea')):
        word = word[:(-1)]
        rv = rv[:(-1)]
        if ((word.endswith(u'gu') and rv.endswith(u'u')) or (word.endswith(u'ci') and rv.endswith(u'i'))):
            word = word[:(-1)]
    elif word.endswith(u'\xe7'):
        word = suffix_replace(word, u'\xe7', u'c')
    word = word.replace(u'a~', u'\xe3').replace(u'o~', u'\xf5')
    return word
