Package nltk :: Package chat
[hide private]
[frames] | no frames]

Source Code for Package nltk.chat

 1  # Natural Language Toolkit: Chatbots 
 2  # 
 3  # Copyright (C) 2001-2011 NLTK Project 
 4  # Authors: Steven Bird <sb@csse.unimelb.edu.au> 
 5  # URL: <http://www.nltk.org/> 
 6  # For license information, see LICENSE.TXT 
 7   
 8  # Based on an Eliza implementation by Joe Strout <joe@strout.net>, 
 9  # Jeff Epler <jepler@inetnebr.com> and Jez Higgins <jez@jezuk.co.uk>. 
10   
11  """ 
12  A class for simple chatbots.  These perform simple pattern matching on sentences 
13  typed by users, and respond with automatically generated sentences. 
14   
15  These chatbots may not work using the windows command line or the 
16  windows IDLE GUI. 
17  """ 
18   
19  from util import * 
20  from eliza import eliza_chat 
21  from iesha import iesha_chat 
22  from rude import rude_chat 
23  from suntsu import suntsu_chat 
24  from zen import zen_chat 
25   
26  bots = [ 
27      (eliza_chat,  'Eliza (psycho-babble)'), 
28      (iesha_chat,  'Iesha (teen anime junky)'), 
29      (rude_chat,   'Rude (abusive bot)'), 
30      (suntsu_chat, 'Suntsu (Chinese sayings)'), 
31      (zen_chat,    'Zen (gems of wisdom)')] 
32   
33 -def chatbots():
34 import sys 35 print 'Which chatbot would you like to talk to?' 36 botcount = len(bots) 37 for i in range(botcount): 38 print ' %d: %s' % (i+1, bots[i][1]) 39 while True: 40 print '\nEnter a number in the range 1-%d: ' % botcount, 41 choice = sys.stdin.readline().strip() 42 if choice.isdigit() and (int(choice) - 1) in range(botcount): 43 break 44 else: 45 print ' Error: bad chatbot number' 46 47 chatbot = bots[int(choice)-1][0] 48 chatbot()
49