-
Notifications
You must be signed in to change notification settings - Fork 148
/
test.py
42 lines (38 loc) · 1.35 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
This script demonstrates how to create a bare-bones, fully functional
chatbot using PyAIML.
"""
import aiml
import sys
# Create a Kernel object.
kern = aiml.Kernel()
# When loading an AIML set, you have two options: load the original
# AIML files, or load a precompiled "brain" that was created from a
# previous run. If no brain file is available, we force a reload of
# the AIML files.
brainLoaded = False
forceReload = False
while not brainLoaded:
if forceReload or (len(sys.argv) >= 2 and sys.argv[1] == "reload"):
# Use the Kernel's bootstrap() method to initialize the Kernel. The
# optional learnFiles argument is a file (or list of files) to load.
# The optional commands argument is a command (or list of commands)
# to run after the files are loaded.
kern.bootstrap(learnFiles="std-startup.xml", commands="load aiml b")
brainLoaded = True
# Now that we've loaded the brain, save it to speed things up for
# next time.
kern.saveBrain("standard.brn")
else:
# Attempt to load the brain file. If it fails, fall back on the Reload
# method.
try:
# The optional branFile argument specifies a brain file to load.
kern.bootstrap(brainFile = "standard.brn")
brainLoaded = True
except:
forceReload = True
# Enter the main input/output loop.
print "\nINTERACTIVE MODE (ctrl-c to exit)"
while(True):
print kern.respond(raw_input("> "))