class documentation

class Chat(object): (source)

Constructor: Chat(pairs, reflections)

View In Hierarchy

Undocumented

Method __init__ 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...
Method converse Undocumented
Method respond Generate a response to the user input.
Method _compile_reflections Undocumented
Method _substitute Substitute words in the string, according to the specified reflections, e.g. "I'm" -> "you are"
Method _wildcards Undocumented
Instance Variable _pairs Undocumented
Instance Variable _reflections Undocumented
Instance Variable _regex Undocumented
def __init__(self, pairs, reflections={}): (source)

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 tupleThe patterns and responses
reflections:dictA mapping between first and second person expressions
Returns
NoneUndocumented
def converse(self, quit='quit'): (source)

Undocumented

def respond(self, str): (source)

Generate a response to the user input.

Parameters
str:strThe string to be mapped
Returns
strUndocumented
def _compile_reflections(self): (source)

Undocumented

def _substitute(self, str): (source)

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

Parameters
str:strThe string to be mapped
Returns
strUndocumented
def _wildcards(self, response, match): (source)

Undocumented

Undocumented

_reflections = (source)

Undocumented

Undocumented