Get started with AIML C# programming (III): Be nice and understand that robot can be naïve!

09 Mar

In previous two blogs (Here and Here), I have shown how to experiment AIML programming, and it is not hard to turn the HelloRobot console into a GUI program. Yes, I did, and found that the robot is smart and fun.

Until, the silly me, typed below:

Me: Marry me!
Robot: …………………………………………………………


It halts, and after a long time … then no response message pops.


What? Kidding me? I just want to let the robot know that! But he has lost connection with me! Why that? How to deal with this elegantly?

To know this, we need go back again to have a look at settings.xml. In there, you can see an item called “timeout”!


Change the value to “10”, rebuild and re-run the WPF application:


Now you see that a time out exception appeared after around 10 seconds, and an error message explains what happened. This is much better, but not the best. So we might try to handle the error (not exception) gracefully.

Original code:

CuteRobotLib.CuteRobot bot = new CuteRobotLib.CuteRobot();
var output = bot.getOutput(input);
if (!string.IsNullOrEmpty(output))
    HistoryListBox.Items.Add("Robot:\t" + output);

Now change it to:

var output = bot.getOutput(input);
if (!string.IsNullOrEmpty(output))
        HistoryListBox.Items.Add("Robot:\t" + "I don't understand what you mean.");
        HistoryListBox.Items.Add("Robot:\t" + output);

Rebuild and re-run the WPF application, now, when you ask the robot to “marry you”, this is handled thoughtfully.


Yes, be nice and considerate. Robot can be naïve as well, and you should be responsible for your code to handle all kinds of exceptions and illogical responses!

Happy coding. Hm, wait, wait, where’s my coffee gone? Ask you robot and see his response!

Leave a comment

Posted by on March 9, 2014 in AI, Programming


Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: