# Buggy code
def stem(self, word):
    """
     Stem an Arabic word and return the stemmed form.
    :param word: string
    :return: string
    """
    # set initial values
    self.is_verb = True
    self.is_noun = True
    self.is_defined = False

    self.suffix_verb_step2a_success = False
    self.suffix_verb_step2b_success = False
    self.suffix_noun_step2c2_success = False
    self.suffix_noun_step1a_success = False
    self.suffix_noun_step2a_success = False
    self.suffix_noun_step2b_success = False
    self.suffixe_noun_step1b_success = False
    self.prefix_step2a_success = False
    self.prefix_step3a_noun_success = False
    self.prefix_step3b_noun_success = False

    modified_word = word
    # guess type and properties
    # checks1
    self.__checks_1(modified_word)
    # checks2
    self.__checks_2(modified_word)
    modified_word = self.__normalize_pre(modified_word)
    if self.is_verb:
        modified_word = self.__Suffix_Verb_Step1(modified_word)
        if self.suffixes_verb_step1_success:
            modified_word = self.__Suffix_Verb_Step2a(modified_word)
            if not self.suffix_verb_step2a_success:
                modified_word = self.__Suffix_Verb_Step2c(modified_word)
            # or next
        else:
            modified_word = self.__Suffix_Verb_Step2b(modified_word)
            if not self.suffix_verb_step2b_success:
                modified_word = self.__Suffix_Verb_Step2a(modified_word)
    if self.is_noun:
        modified_word = self.__Suffix_Noun_Step2c2(modified_word)
        if not self.suffix_noun_step2c2_success:
            if not self.is_defined:
                modified_word = self.__Suffix_Noun_Step1a(modified_word)
                # if self.suffix_noun_step1a_success:
                modified_word = self.__Suffix_Noun_Step2a(modified_word)
                if not self.suffix_noun_step2a_success:
                    modified_word = self.__Suffix_Noun_Step2b(modified_word)
                if (
                    not self.suffix_noun_step2b_success
                    and not self.suffix_noun_step2a_success
                ):
                    modified_word = self.__Suffix_Noun_Step2c1(modified_word)
                # or next ? todo : how to deal with or next
            else:
                modified_word = self.__Suffix_Noun_Step1b(modified_word)
                if self.suffixe_noun_step1b_success:
                    modified_word = self.__Suffix_Noun_Step2a(modified_word)
                    if not self.suffix_noun_step2a_success:
                        modified_word = self.__Suffix_Noun_Step2b(modified_word)
                    if (
                        not self.suffix_noun_step2b_success
                        and not self.suffix_noun_step2a_success
                    ):
                        modified_word = self.__Suffix_Noun_Step2c1(modified_word)
                else:
                    if not self.is_defined:
                        modified_word = self.__Suffix_Noun_Step2a(modified_word)
                    modified_word = self.__Suffix_Noun_Step2b(modified_word)
        modified_word = self.__Suffix_Noun_Step3(modified_word)
    if not self.is_noun and self.is_verb:
        modified_word = self.__Suffix_All_alef_maqsura(modified_word)

    # prefixes
    modified_word = self.__Prefix_Step1(modified_word)
    modified_word = self.__Prefix_Step2a(modified_word)
    if not self.prefix_step2a_success:
        modified_word = self.__Prefix_Step2b(modified_word)
    modified_word = self.__Prefix_Step3a_Noun(modified_word)
    if not self.prefix_step3a_noun_success and self.is_noun:
        modified_word = self.__Prefix_Step3b_Noun(modified_word)
    else:
        if not self.prefix_step3b_noun_success and self.is_verb:
            modified_word = self.__Prefix_Step3_Verb(modified_word)
            modified_word = self.__Prefix_Step4_Verb(modified_word)

    # post normalization stemming
    modified_word = self.__normalize_post(modified_word)
    stemmed_word = modified_word
    return stemmed_word


# Traceback (AttributeError)
(anaconda2-4.4.0) richard-balmer-macbook:~ richardbalmer$ pip freeze | grep nltk
nltk==3.2.5
(anaconda2-4.4.0) richard-balmer-macbook:~ richardbalmer$ ipython
Python 2.7.13 |Anaconda custom (x86_64)| (default, Dec 20 2016, 23:05:08)
Type "copyright", "credits" or "license" for more information.

IPython 5.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from nltk.stem.snowball import SnowballStemmer

In [2]: stemmer = SnowballStemmer('arabic')

In [3]: stemmer.stem(u'تسدد')
Out[3]: u'\u062a\u0633\u062f\u062f'

In [4]: stemmer.stem(u'من')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-ffa733106049> in <module>()
----> 1 stemmer.stem(u'من')

/Users/richardbalmer/.pyenv/versions/anaconda2-4.4.0/lib/python2.7/site-packages/nltk/stem/snowball.pyc in stem(self, word)
762                 modified_word = self.__Suffix_Verb_Step2b(modified_word)
763                 if not self.suffix_verb_step2b_success:
--> 764                     modified_word = self.__Suffix_Verb_Step2a(modified_word)
765         if self.is_noun:
766             modified_word = self.__Suffix_Noun_Step2c2(modified_word)

/Users/richardbalmer/.pyenv/versions/anaconda2-4.4.0/lib/python2.7/site-packages/nltk/stem/snowball.pyc in __Suffix_Verb_Step2a(self, token)
533                     break
534
--> 535                 if suffix in self.__conjugation_suffix_verb_present and len(token) > 5:
536                     token = token[:-2]  # present
537                     self.suffix_verb_step2a_success = True

AttributeError: 'ArabicStemmer' object has no attribute '_ArabicStemmer__conjugation_suffix_verb_present'

# Fixed code
def stem(self, word):
    """
     Stem an Arabic word and return the stemmed form.
    :param word: string
    :return: string
    """
    # set initial values
    self.is_verb = True
    self.is_noun = True
    self.is_defined = False

    self.suffix_verb_step2a_success = False
    self.suffix_verb_step2b_success = False
    self.suffix_noun_step2c2_success = False
    self.suffix_noun_step1a_success = False
    self.suffix_noun_step2a_success = False
    self.suffix_noun_step2b_success = False
    self.suffixe_noun_step1b_success = False
    self.prefix_step2a_success = False
    self.prefix_step3a_noun_success = False
    self.prefix_step3b_noun_success = False

    modified_word = word
    # guess type and properties
    # checks1
    self.__checks_1(modified_word)
    # checks2
    self.__checks_2(modified_word)
    # Pre_Normalization
    modified_word = self.__normalize_pre(modified_word)
    # Avoid stopwords
    if modified_word in self.stopwords or len(modified_word) <= 2:
        return modified_word
    # Start stemming
    if self.is_verb:
        modified_word = self.__Suffix_Verb_Step1(modified_word)
        if self.suffixes_verb_step1_success:
            modified_word = self.__Suffix_Verb_Step2a(modified_word)
            if not self.suffix_verb_step2a_success:
                modified_word = self.__Suffix_Verb_Step2c(modified_word)
            # or next TODO: How to deal with or next instruction
        else:
            modified_word = self.__Suffix_Verb_Step2b(modified_word)
            if not self.suffix_verb_step2b_success:
                modified_word = self.__Suffix_Verb_Step2a(modified_word)
    if self.is_noun:
        modified_word = self.__Suffix_Noun_Step2c2(modified_word)
        if not self.suffix_noun_step2c2_success:
            if not self.is_defined:
                modified_word = self.__Suffix_Noun_Step1a(modified_word)
                # if self.suffix_noun_step1a_success:
                modified_word = self.__Suffix_Noun_Step2a(modified_word)
                if not self.suffix_noun_step2a_success:
                    modified_word = self.__Suffix_Noun_Step2b(modified_word)
                if (
                    not self.suffix_noun_step2b_success
                    and not self.suffix_noun_step2a_success
                ):
                    modified_word = self.__Suffix_Noun_Step2c1(modified_word)
                # or next ? todo : how to deal with or next
            else:
                modified_word = self.__Suffix_Noun_Step1b(modified_word)
                if self.suffixe_noun_step1b_success:
                    modified_word = self.__Suffix_Noun_Step2a(modified_word)
                    if not self.suffix_noun_step2a_success:
                        modified_word = self.__Suffix_Noun_Step2b(modified_word)
                    if (
                        not self.suffix_noun_step2b_success
                        and not self.suffix_noun_step2a_success
                    ):
                        modified_word = self.__Suffix_Noun_Step2c1(modified_word)
                else:
                    if not self.is_defined:
                        modified_word = self.__Suffix_Noun_Step2a(modified_word)
                    modified_word = self.__Suffix_Noun_Step2b(modified_word)
        modified_word = self.__Suffix_Noun_Step3(modified_word)
    if not self.is_noun and self.is_verb:
        modified_word = self.__Suffix_All_alef_maqsura(modified_word)

    # prefixes
    modified_word = self.__Prefix_Step1(modified_word)
    modified_word = self.__Prefix_Step2a(modified_word)
    if not self.prefix_step2a_success:
        modified_word = self.__Prefix_Step2b(modified_word)
    modified_word = self.__Prefix_Step3a_Noun(modified_word)
    if not self.prefix_step3a_noun_success and self.is_noun:
        modified_word = self.__Prefix_Step3b_Noun(modified_word)
    else:
        if not self.prefix_step3b_noun_success and self.is_verb:
            modified_word = self.__Prefix_Step3_Verb(modified_word)
            modified_word = self.__Prefix_Step4_Verb(modified_word)

    # post normalization stemming
    modified_word = self.__normalize_post(modified_word)
    stemmed_word = modified_word
    return stemmed_word