background
Using filters, you can effectively create a storage adapters that is connected to the Chatterbot base query (base queries) How to create a new filter for Chatterbot
The following code is the framework for all filter, which inherits from the filter class of Chatterbot and implements its function named Filter_selection.
Example code:
From chatterbot.filters import Filter
class Myfilter (filter):
def filter_selection (self, Chatterbot):
# ...
return query
Filter Queries
Filters uses the storage adapter query object to create a query that can be evaluated by adapter. There are several methods available for querying today:
1:statement_text_equals (statement_text)
The Query method returns the current query and the statement with the constraint Text property added (the statement must be equal to the parameter specified in the test).
2:statement_text_not_in (statements)
The Query method accepts a sequence of text statements and returns the current query with a constraint attribute (which is constrained by the statement returned is not in the specified list).
3:statement_response_list_contains (statement_text)
The query method receives a single text statement that returns the current query as constrained, and its constraint is that the returned statement must contain the specified text as a response.
4:statement_response_list_equals (Response_list)
The query method receives a sequence of text statements that return a constrained current query, and its constraint is that the return result must have an exact match in the response value list. Filter Support
Not all storage adapters support filter. When storage adapter does not support filters, the query produced by filter is ignored directly in the use of storage adapter.
Storage adapter supports filters only if it supports queries. You can determine whether the storage Adapte supports queries by checking that the Dapter_supports_queries property is true. Repetitive response Filter (repetitive response filter)
function definition:
Chatterbot.filters.RepetitiveResponseFilter ()
The filter is used to eliminate potential repetitive responses to avoid repeated replies from the chat bot.
Code use:
chatbot = Chatbot ("My chatterbot", filters= "Chatterbot.filters.RepetitiveResponseFilter" )