Chat Robot Learning Note -3-filter

Source: Internet
Author: User
Tags function definition chatterbot
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" )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.