I am working AIML chatbot with Python Flask as User Interface. I found the problem when I put any wildcard symbol in AIML like '*' or '_' at the beginning of the pattern, that particular phase always unable to match with my pattern.
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0">
<category>
<pattern>FIST</pattern>
<template>The Faculty of Information Science and Technology (FIST) is one of the major academic units in the university.
</template>
</category>
<category>
<pattern>FIST _</pattern>
<template><srai>FIST</srai></template>
</category>
<category>
<pattern>_ FIST</pattern>
<template>
<srai>FIST</srai>
</template>
</category>
</aiml>
The wildcard symbol only able to recognise at the back of the phase but it unable to return the result when I put the wildcard symbol at the beginning of the pattern.
This is my python code that connect with AIML database:
from flask import Flask, render_template, request
import aiml
from autocorrect import Speller
spell = Speller()
app = Flask(__name__)
k = aiml.Kernel()
print("Parsing aiml files")
k.bootstrap(learnFiles="./pretrained_model/learningFileList.aiml", commands="load aiml")
@app.route("/")
def home():
return render_template("index.html")
@app.route("/get")
def get_bot_response():
specialWord = ['FIST', 'AI', 'BIT', 'BCS', 'BS']
query = request.args.get('msg')
querySplit = query.split()
print(querySplit)
commonElement = list(set(querySplit).intersection(specialWord))
queryExclude = [i for i in querySplit if i not in commonElement]
print(queryExclude)
query = [spell(w) for w in queryExclude]
print(query)
for i in commonElement:
index = querySplit.index(i)
query.insert(index, i)
print('The index of', i, 'in the list is:', index)
question = " ".join(query)
print(question)
response = k.respond(question)
if response:
return (str(response))
else:
return (str(":)"))
if __name__ == "__main__":
app.run(host='127.0.0.1', port='5000')