Working with AIML and Python

To check whether the module is properly installed on your machine, open a Python IDLE and import the aiml module:

>>> import aiml

If the module is imported correctly, it will not show any error and comes to the next line. Then, we can confirm that the installation is correct.

The most important class we are handling in the aiml module is Kernel(). We are mainly using this class to learn from AIML files and get a response from the AIML dataset to user input. The following line will create an object of the aiml.Kernel() class:

>>> mybot = aiml.Kernel()

After creating the Kernel() object, we can assign the robot name using the following command. We will assign Chefbot as the name for this robot:

>>> mybot.setBotPredicate("name","Chefbot") ...

Get Learning Robotics Using Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.