0

I'm starting a project with Python which uses AIML, when I run the script It gives me a 'Not match found' error. This is the Python code:

import aiml
kernel = aiml.Kernel()
kernel.learn("bot.aiml")
while True:
    print kernel.respond(raw_input("\n>>"))

Just a simple AIML kernel. Is it something wrong with it?

5 Answers5

0

I have a better python script if you are interested

import aiml
import sys <br>

brainLoaded = False
forceReload = False
while not brainLoaded:
    if forceReload or (len(sys.argv) >= 2 and sys.argv[1] == "reload"):

        kern.bootstrap(learnFiles="Database.xml", commands="load aiml b")
        brainLoaded = True
        kern.saveBrain("Cache.brn")
    else:
        # Attempt to load the brain file.  If it fails, fall back on the Reload
        try:
            # It is our cache file.
            kern.bootstrap(brainFile = "Cache.brn")
            brainLoaded = True
        except:
            forceReload = True

# Enter the main input/output loop.
print "Enter your message for the chatbot"
while(True):
    print kern.respond(raw_input("> "))

Note: You need to create a folder Database where you place your AIML files and a file Database.xml

MrLys
  • 28
  • 4
0

"No match found for input" warning occurs because because "bot.aiml" doesn't have a matching output for your input. Try to include a default response like the following:

<category>
    <pattern>*</pattern>
    <template>
        Sorry. I didn't quite get that.
    </template>
</category>
Haris M E
  • 26
  • 5
0

Try Removing the 'print' statement in the code

import aiml
kernel = aiml.Kernel()
kernel.learn("bot.aiml")
while True:
     kernel.respond(raw_input("\n>>"))
rawplutonium
  • 386
  • 5
  • 15
0

You have to write the sentence in .aiml in capital letter into the <pattern> tag. But you can put your input both in smaller letter and capital letter. Otherwise you will get the error like that. For example:

<category>
    <pattern>WHAT IS YOUR NAME ?</pattern>
    <template>My name is robot.</template>
</category
0

Well, if anyone needs it for Python 3 what should be done is just a change in the syntax of the print function. In python2 it accepts the function without parentheses, but in python3 it is mandatory to use it.

Another observation is that the raw_input() function has been renamed to input() in python3.

So the solution to resolve this syntax error is quite simple:

while True:
    print(kernel.respond(input("\n>>")))

We added the parentheses to the print function including the content to be displayed and started to use the input() function, since there is no more raw_input() in python3.