As we've already discussed, aiml_server is responsible for loading and saving the AIML and AIM brain files. It is subscribed to the /chatter topic, which is the input of the AIML interpreter and publishes the /response topic, which is the response from the AIML interpreter. This is the main code snippet of aiml_server.py:
def load_aiml(xml_file): data_path = rospy.get_param("aiml_path") print data_path os.chdir(data_path) if os.path.isfile("standard.brn"): mybot.bootstrap(brainFile = "standard.brn") else: mybot.bootstrap(learnFiles = xml_file, commands = "load aiml b") mybot.saveBrain("standard.brn") def callback(data): input = data.data response = mybot.respond(input) rospy.loginfo("I heard:: %s",data.data) rospy.loginfo("I spoke:: %s",response) response_publisher.publish(response) def listener(): rospy.loginfo("Starting ROS AIML Server") rospy.Subscriber("chatter", String, callback) # spin() simply keeps python from exiting until this node is stopped rospy.spin() if __name__ == '__main__': load_aiml('startup.xml') listener()
This ROS node is doing the same thing as the code that we used to load and save the AIML files. That code is converted into a ROS node that can accept input and send the response through a topic.
You can clone the source code discussed in the section from the following Git repository: https://github.com/qboticslabs/ros_robotics_projects