How to create a new filter for ChatterBot¶
This is the basic outline of the code that your filter will need to follow. Each filter should inherit from ChatterBot’s Filter class and implement a method called filter_selection. Everything else that your filter does is up to you.
from chatterbot.filters import Filter class MyFilter(Filter): def filter_selection(self, chatterbot): # ... return query
Filters use a storage adapter’s query object to build a query that the adapter can evaluate. The available query methods currently are:
This query method returns the current query with the added constraint that the text attribute of any statement returned must be equal to the text specified in the parameter.
This query method takes a list of statement text values and returns the current query with the added constraint that any statements returned cannot exist in the list specified.
This query method takes a single statement text value and returns the current query with the added constraint that any statements returned must contain the specified text as a response.
This query method takes a list of statement text values and returns the current query with the added constraint that any statements returned must have an exactly matching list of response values.
Not all storage adapters support filters. If a storage adapter does not support filters, then queries generated by filters will be ignored when using that storage adapter.
A storage adapter only supports filters if it supports querying. You can tell if a storage adapter supports querying by checking if its adapter_supports_queries property is set to true.