natural language toolkit chatbots c 20012023 nltk project s steven bird stevenbird1gmail com url https www nltk org for license information see license txt based on an eliza implementation by joe strout joestrout net jeff epler jeplerinetnebr com and jez higgins jezjezuk co uk a class for simple chatbots these perform simple pattern matching on sentences typed by users and respond with automatically generated sentences these chatbots may not work using the windows command line or the windows idle gui natural language toolkit chatbots c 2001 2023 nltk project s steven bird stevenbird1 gmail com url https www nltk org for license information see license txt based on an eliza implementation by joe strout joe strout net jeff epler jepler inetnebr com and jez higgins jez jezuk co uk a class for simple chatbots these perform simple pattern matching on sentences typed by users and respond with automatically generated sentences these chatbots may not work using the windows command line or the windows idle gui
from nltk.chat.eliza import eliza_chat
from nltk.chat.iesha import iesha_chat
from nltk.chat.rude import rude_chat
from nltk.chat.suntsu import suntsu_chat
from nltk.chat.util import Chat
from nltk.chat.zen import zen_chat

bots = [
    (eliza_chat, "Eliza (psycho-babble)"),
    (iesha_chat, "Iesha (teen anime junky)"),
    (rude_chat, "Rude (abusive bot)"),
    (suntsu_chat, "Suntsu (Chinese sayings)"),
    (zen_chat, "Zen (gems of wisdom)"),
]


def chatbots():
    print("Which chatbot would you like to talk to?")
    botcount = len(bots)
    for i in range(botcount):
        print("  %d: %s" % (i + 1, bots[i][1]))
    while True:
        choice = input(f"\nEnter a number in the range 1-{botcount}: ").strip()
        if choice.isdigit() and (int(choice) - 1) in range(botcount):
            break
        else:
            print("   Error: bad chatbot number")

    chatbot = bots[int(choice) - 1][0]
    chatbot()