Package peppy :: Package nltk_lite :: Package chat :: Package nltk_lite :: Module chat :: Class Chat
[frames] | no frames]

Class Chat

object --+
         |
        Chat

Instance Methods
None
__init__(self, pairs, reflections={})
Initialize the chatbot.
string
respond(self, str)
Generate a response to the user input.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties

Inherited from object: __class__

Method Details

__init__(self, pairs, reflections={})
(Constructor)

 

Initialize the chatbot. Pairs is a list of patterns and responses. Each pattern is a regular expression matching the user's statement or question, e.g. r'I like (.*)'. For each such pattern a list of possible responses is given, e.g. ['Why do you like %1', 'Did you ever dislike %1']. Material which is matched by parenthesized sections of the patterns (e.g. .*) is mapped to the numbered positions in the responses, e.g. %1.

Parameters:
  • pairs (list of tuple) - The patterns and responses
  • reflections (dict) - A mapping between first and second person expressions
Returns: None
Overrides: object.__init__

respond(self, str)

 

Generate a response to the user input.

Parameters:
  • str (string) - The string to be mapped
Returns: string