Book Image

Learning Robotics using Python

Book Image

Learning Robotics using Python

Overview of this book

Table of Contents (19 chapters)
Learning Robotics Using Python
About the Author
About the Reviewers

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")

The next step is to learn AIML files. We can load either a single AIML file or a group of AIML files. To load a single AIML file, we can use the following command. Note that the sample.aiml file must be...