RSS

Get started with AIML C# programming (I): Just say hello to the robot

08 Mar

In this series of articles, I am about to keep a note on my recent trials to program AIML using C#. AIML, or Artificial Intelligence Markup Language, is an XML dialect for creating natural language software agents. With AIML, you can design your own soft robot with ease!

  • Create a library project and add a class called CuteRobot. The reason for create a library is to reuse such robot code later. You may however directly put it in the main application as you like.
public class CuteRobot
{
    const string UserId = "CityU.Scm.David";
    private Bot AimlBot;
    private User myUser;

    public CuteRobot()
    {
        AimlBot = new Bot();
        myUser = new User(UserId, AimlBot);
        Initialize();
    }

    // Loads all the AIML files in the \AIML folder         
    public void Initialize()
    {
        AimlBot.loadSettings();
        AimlBot.isAcceptingUserInput = false;
        AimlBot.loadAIMLFromFiles();
        AimlBot.isAcceptingUserInput = true;
    }

    // Given an input string, finds a response using AIMLbot lib
    public String getOutput(String input)
    {
        Request r = new Request(input, myUser, AimlBot);
        Result res = AimlBot.Chat(r);
        return (res.Output);
    }
}

  • You need:
    • Add a reference to the AIMLbot.dll to the project
    • You need also to copy the aiml and config folders to the bin folder of the library project

image

  • Create a console application, add reference to the above library project, in the Main class:

class Program
{
    static CuteRobot bot;
    static void Main(string[] args)
    {
        bot = new CuteRobot();
        string input = "Hello, what is your name";
        var output = bot.getOutput(input);
        Console.WriteLine(input);
        Console.WriteLine(output);
        Console.ReadKey();
    }
}

Also copy the aiml and config folders to the bin folder of the console application’s bin folder. Now run the application, you might see:

image

Ha! It worked! When you ask “hello, what is your name?”, the robot answers: “Hello there. My name is Unknown”! Smart? Cool?

Even though it is weird that the robot says his name is “Unknown”, it worked! In the next blog, I will focus on how to customize the robot’s name and other attributes.

Happy coding!

Advertisements
 
6 Comments

Posted by on March 8, 2014 in AI, Programming

 

Tags: , , , , , , , , ,

6 responses to “Get started with AIML C# programming (I): Just say hello to the robot

  1. Ravindra

    September 16, 2015 at 5:19 pm

    Hi,

    I am using AIML and when I am writing a console app its working fine. But when I am using AIML for writing API and when I am deploying, I am unable to loadSetting of AIML. The error I get is unable to find Specified file even though that file exists. I have been trying to solve this since past many days. Can you please help me.

    Thanks in advance.

     
  2. Michael

    February 6, 2016 at 8:26 pm

    Hello,i have some question about AIML.Does it work only with english?if no,how to change language of the massages?

     
  3. 2k16 coins

    May 11, 2016 at 9:33 am

    You have the best web sites

     
  4. Alfy

    March 17, 2017 at 1:35 pm

    @Michael you will need to write your own AIML

     

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: