Exemplo n.º 1
0
    def untrain(self, msg, is_spam):
        """Untrain bayes with a message.

        msg can be a string, a file object, or a Message object.

        is_spam should be True if the message is spam, False if not.

        """

        self.bayes.unlearn(tokenize(msg), is_spam)
Exemplo n.º 2
0
    def _scoremsg(self, msg, evidence=False):
        """Score a Message.

        msg can be a string, a file object, or a Message object.

        Returns the probability the message is spam.  If evidence is
        true, returns a tuple: (probability, clues), where clues is a
        list of the words which contributed to the score.

        """

        return self.bayes.spamprob(tokenize(msg), evidence)
Exemplo n.º 3
0
    def train(self, msg, is_spam, add_header=False):
        """Train bayes with a message.

        msg can be a string, a file object, or a Message object.

        is_spam should be 1 if the message is spam, 0 if not.

        If add_header is True, add a header with how it was trained (in
        case we need to untrain later)

        """

        self.bayes.learn(tokenize(msg), is_spam)
        if add_header:
            if is_spam:
                trained = options["Headers", "header_spam_string"]
            else:
                trained = options["Headers", "header_ham_string"]
            del msg[options["Headers", "trained_header_name"]]
            msg.add_header(options["Headers", "trained_header_name"], trained)