(self, word)
return word
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
Stem a Portuguese word and return the stemmed form.
Stem a Portuguese word and return the stemmed form .
def stem(self, word):
        """
        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

        """
        word = word.lower()

        step1_success = False
        step2_success = False

        word = (word.replace(u("\xE3"), "a~")
                    .replace(u("\xF5"), "o~"))

        r1, r2 = self._r1r2_standard(word, self.__vowels)
        rv = self._rv_standard(word, self.__vowels)

        # STEP 1: Standard suffix removal
        for suffix in self.__step1_suffixes:
            if word.endswith(suffix):
                if suffix == "amente" and r1.endswith(suffix):
                    step1_success = True

                    word = word[:-6]
                    r2 = r2[:-6]
                    rv = rv[:-6]

                    if r2.endswith("iv"):
                        word = word[:-2]
                        r2 = r2[:-2]
                        rv = rv[:-2]

                        if r2.endswith("at"):
                            word = word[:-2]
                            rv = rv[:-2]

                    elif r2.endswith(("os", "ic", "ad")):
                        word = word[:-2]
                        rv = rv[:-2]

                elif (suffix in ("ira", "iras") and rv.endswith(suffix) and
                      word[-len(suffix) - 1:-len(suffix)] == "e"):
                    step1_success = True

                    word = "".join((word[:-len(suffix)], "ir"))
                    rv = "".join((rv[:-len(suffix)], "ir"))

                elif r2.endswith(suffix):
                    step1_success = True

                    if suffix in (u("log\xEDa"), u("log\xEDas")):
                        word = word[:-2]
                        rv = rv[:-2]

                    elif suffix in (u("uci\xF3n"), "uciones"):
                        word = "".join((word[:-len(suffix)], "u"))
                        rv = "".join((rv[:-len(suffix)], "u"))

                    elif suffix in (u("\xEAncia"), u("\xEAncias")):
                        word = "".join((word[:-len(suffix)], "ente"))
                        rv = "".join((rv[:-len(suffix)], "ente"))

                    elif suffix == "mente":
                        word = word[:-5]
                        r2 = r2[:-5]
                        rv = rv[:-5]

                        if r2.endswith(("ante", "avel", u("\xEDvel"))):
                            word = word[:-4]
                            rv = rv[:-4]

                    elif suffix in ("idade", "idades"):
                        word = word[:-len(suffix)]
                        r2 = r2[:-len(suffix)]
                        rv = rv[:-len(suffix)]

                        if r2.endswith(("ic", "iv")):
                            word = word[:-2]
                            rv = rv[:-2]

                        elif r2.endswith("abil"):
                            word = word[:-4]
                            rv = rv[:-4]

                    elif suffix in ("iva", "ivo", "ivas", "ivos"):
                        word = word[:-len(suffix)]
                        r2 = r2[:-len(suffix)]
                        rv = rv[:-len(suffix)]

                        if r2.endswith("at"):
                            word = word[:-2]
                            rv = rv[:-2]
                    else:
                        word = word[:-len(suffix)]
                        rv = rv[:-len(suffix)]
                break

        # STEP 2: Verb suffixes
        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

        # STEP 3
        if step1_success or step2_success:
            if rv.endswith("i") and word[-2] == "c":
                word = word[:-1]
                rv = rv[:-1]

        ### STEP 4: Residual suffix
        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

        # STEP 5
        if rv.endswith(("e", u("\xE9"), u("\xEA"))):
            word = word[:-1]
            rv = rv[:-1]

            if ((word.endswith("gu") and rv.endswith("u")) or
                (word.endswith("ci") and rv.endswith("i"))):
                word = word[:-1]

        elif word.endswith(u("\xE7")):
            word = "".join((word[:-1], "c"))

        word = word.replace("a~", u("\xE3")).replace("o~", u("\xF5"))
        return word
def stem ( self , word ) : word = word . lower ( ) step1_success = False step2_success = False word = ( word . replace ( u ( "\xE3" ) , "a~" ) . replace ( u ( "\xF5" ) , "o~" ) ) r1 , r2 = self . _r1r2_standard ( word , self . __vowels ) rv = self . _rv_standard ( word , self . __vowels ) # STEP 1: Standard suffix removal for suffix in self . __step1_suffixes : if word . endswith ( suffix ) : if suffix == "amente" and r1 . endswith ( suffix ) : step1_success = True word = word [ : - 6 ] r2 = r2 [ : - 6 ] rv = rv [ : - 6 ] if r2 . endswith ( "iv" ) : word = word [ : - 2 ] r2 = r2 [ : - 2 ] rv = rv [ : - 2 ] if r2 . endswith ( "at" ) : word = word [ : - 2 ] rv = rv [ : - 2 ] elif r2 . endswith ( ( "os" , "ic" , "ad" ) ) : word = word [ : - 2 ] rv = rv [ : - 2 ] elif ( suffix in ( "ira" , "iras" ) and rv . endswith ( suffix ) and word [ - len ( suffix ) - 1 : - len ( suffix ) ] == "e" ) : step1_success = True word = "" . join ( ( word [ : - len ( suffix ) ] , "ir" ) ) rv = "" . join ( ( rv [ : - len ( suffix ) ] , "ir" ) ) elif r2 . endswith ( suffix ) : step1_success = True if suffix in ( u ( "log\xEDa" ) , u ( "log\xEDas" ) ) : word = word [ : - 2 ] rv = rv [ : - 2 ] elif suffix in ( u ( "uci\xF3n" ) , "uciones" ) : word = "" . join ( ( word [ : - len ( suffix ) ] , "u" ) ) rv = "" . join ( ( rv [ : - len ( suffix ) ] , "u" ) ) elif suffix in ( u ( "\xEAncia" ) , u ( "\xEAncias" ) ) : word = "" . join ( ( word [ : - len ( suffix ) ] , "ente" ) ) rv = "" . join ( ( rv [ : - len ( suffix ) ] , "ente" ) ) elif suffix == "mente" : word = word [ : - 5 ] r2 = r2 [ : - 5 ] rv = rv [ : - 5 ] if r2 . endswith ( ( "ante" , "avel" , u ( "\xEDvel" ) ) ) : word = word [ : - 4 ] rv = rv [ : - 4 ] elif suffix in ( "idade" , "idades" ) : word = word [ : - len ( suffix ) ] r2 = r2 [ : - len ( suffix ) ] rv = rv [ : - len ( suffix ) ] if r2 . endswith ( ( "ic" , "iv" ) ) : word = word [ : - 2 ] rv = rv [ : - 2 ] elif r2 . endswith ( "abil" ) : word = word [ : - 4 ] rv = rv [ : - 4 ] elif suffix in ( "iva" , "ivo" , "ivas" , "ivos" ) : word = word [ : - len ( suffix ) ] r2 = r2 [ : - len ( suffix ) ] rv = rv [ : - len ( suffix ) ] if r2 . endswith ( "at" ) : word = word [ : - 2 ] rv = rv [ : - 2 ] else : word = word [ : - len ( suffix ) ] rv = rv [ : - len ( suffix ) ] break # STEP 2: Verb suffixes 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 # STEP 3 if step1_success or step2_success : if rv . endswith ( "i" ) and word [ - 2 ] == "c" : word = word [ : - 1 ] rv = rv [ : - 1 ] ### STEP 4: Residual suffix 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 # STEP 5 if rv . endswith ( ( "e" , u ( "\xE9" ) , u ( "\xEA" ) ) ) : word = word [ : - 1 ] rv = rv [ : - 1 ] if ( ( word . endswith ( "gu" ) and rv . endswith ( "u" ) ) or ( word . endswith ( "ci" ) and rv . endswith ( "i" ) ) ) : word = word [ : - 1 ] elif word . endswith ( u ( "\xE7" ) ) : word = "" . join ( ( word [ : - 1 ] , "c" ) ) word = word . replace ( "a~" , u ( "\xE3" ) ) . replace ( "o~" , u ( "\xF5" ) ) return word