API

antispam.score(msg)[source]

Score the message based on the built-in model.

Parameters:msg – Message to be scored in string format.
antispam.is_spam(msg)[source]

Decide whether the message is a spam or not based on the built-in model.

Parameters:msg – Message to be classified in string format.

antispam.Model

class antispam.Model(file_path=None, create_new=False)[source]

Save & Load the model in/from the file system using Python’s json module.

Constructs a Model object by the indicated file_path, if the file does not exist, create a new file and contruct a empty model.

Parameters:
  • file_path – (optional) Path for the model file indicated, if path is not indicated, use the built-in model file provided by the author, which is located in the antispam package folder.
  • create_new – (option) Boolean. If True, create an empty model. file_path will be used when saving the model. If there is an existing model file on the path, the existing model file will be overwritten.
load(file_path=None)[source]

Load the serialized file from the specified file_path, and return spam_count_total, ham_count_total and token_table.

Parameters:file_path – (optional) Path for the model file. If the path does not exist, create a new one.
save()[source]

Serialize the model using Python’s json module, and save the serialized modle as a file which is indicated by self.file_path.

antispam.Detector

class antispam.Detector(path=None, create_new=False)[source]

A baysian spam filter

Parameters:path – (optional) Path for the model file, will be passes to Model and construct a Model object based on path.
train(msg, is_spam)[source]

Train the model.

Parameters:
  • msg – Message in string format.
  • is_spam – Boolean. If True, train the message as a spam, if False, train the message as a ham.
score(msg)[source]

Calculate and return the spam score of a msg. The higher the score, the stronger the liklihood that the msg is a spam is.

Parameters:msg – Message in string format.
save()[source]

Save self.model based on self.model.file_path.