def train(self, message, is_spam):
        totals = self.storage.totals
        tokens = self.storage.tokens
        if is_spam:
            totals['spam'] += 1
        else:
            totals['ham'] += 1
        
        # compute hashes of uppercase words
        hashes = map(lambda x: hash(string.upper(x)), \
                     self.__get_words_list(message))
        for h in hashes:
            try:
                t = tokens[h]
                if is_spam:
                    t[1] += 1  # spam_count
                else:
                    t[0] += 1  # ham_count
            except KeyError:
                # no word in storage
                spam_count = 1 if is_spam else 0
                ham_count = 1 - spam_count
                tokens[h] = [ham_count, spam_count]
        self.storage.save_if_needed()
Train database with message
dataset/ETHPy150Open dchest/pybayesantispam/bayes.py/Bayes.train