I am trying the PyAiml package to write a chatbot. I wrote a very basic program with all those default aiml files from A.L.I.C.E. Everything works fine so far except the <that> tag. I thought it was the session problem. Then I fixed the session. But still no luck with <that> tag for contextual conversation. Anyone knows how to make it work? Or the PyAiml has some bug with <that> tag parsing?
Here is my bot program and a very minimal aiml file I am testing with:
testbot.py
import aiml
import marshal
import os
from pprint import pprint
BOOTSTRAP_FILE = "/var/www/html/chatbot/std-startup.xml"
BOT_SESSION_PATH = "/var/www/html/chatbot/"
sess_id = 'user_id_moshfiqur'
while True:
k = aiml.Kernel()
k.bootstrap(learnFiles=BOOTSTRAP_FILE, commands="load aiml b")
if os.path.isfile(BOT_SESSION_PATH + sess_id + ".ses"):
sessionFile = file(BOT_SESSION_PATH + sess_id + ".ses", "rb")
sessionData = marshal.load(sessionFile)
sessionFile.close()
for pred, value in sessionData.items():
k.setPredicate(pred, value, sess_id)
response = k.respond(raw_input(">> "), sessionID=sess_id)
sessionData = k.getSessionData(sess_id)
pprint(sessionData)
sessionFile = file(BOT_SESSION_PATH + sess_id + ".ses", "wb")
marshal.dump(sessionData, sessionFile)
sessionFile.close()
pprint("<< " + response)
minimal.aiml
<aiml version="1.0.1" encoding="UTF-8">
<category>
<pattern>TEST1</pattern>
<template>testing one</template>
</category>
<category>
<pattern>TEST2</pattern>
<that>testing one</that>
<template>Success</template>
</category>
</aiml>