Preprocessors

ChatterBot’s preprocessors are simple functions that modify the input statement that a chat bot receives before the statement gets processed by the logic adaper.

Here is an example of how to set preprocessors. The preprocessors parameter should be a list of strings of the import paths to your preprocessors.

chatbot = ChatBot(
    'Bob the Bot',
    preprocessors=[
        'chatterbot.preprocessors.clean_whitespace'
    ]
)

Preprocessor functions

ChatterBot comes with several built-in preprocessors.

chatterbot.preprocessors.clean_whitespace(chatbot, statement)[source]

Remove any consecutive whitespace characters from the statement text.

chatterbot.preprocessors.unescape_html(chatbot, statement)[source]

Convert escaped html characters into unescaped html characters. For example: “&lt;b&gt;” becomes “<b>”.

chatterbot.preprocessors.convert_to_ascii(chatbot, statement)[source]

Converts unicode characters to ASCII character equivalents. For example: “på fédéral” becomes “pa federal”.

Creating new preprocessors

It is simple to create your own preprocessors. A preprocessor is just a function with a few requirements.

  1. It must take two parameters, the first is a ChatBot instance, the second is a Statement instance.
  2. It must return a statement instance.