Package nltk :: Package chat :: Module util :: Class Chat
[hide private]
[frames] | no frames]

Class Chat

source code

object --+
         |
        Chat

Instance Methods [hide private]
None
__init__(self, pairs, reflections={})
Initialize the chatbot.
source code
string
_substitute(self, str)
Substitute words in the string, according to the specified reflections, e.g.
source code
 
_wildcards(self, response, match) source code
string
respond(self, str)
Generate a response to the user input.
source code
 
converse(self, quit='quit') source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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

source code 

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__

_substitute(self, str)

source code 

Substitute words in the string, according to the specified reflections, e.g. "I'm" -> "you are"

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

respond(self, str)

source code 

Generate a response to the user input.

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