Sunday, December 6, 2009

Create a "Hello" CML bot

To create a simple CML bot, you will need Java runtime, CML development toolkit and your favorite text editor. This toolkit comes with a CML interpret Cindy, Plugin examples and some CML examples.
  1. To run Cindy, you need to have "java" in your PATH
  2. Run CindyGui.bat (for Windows) or CindyGui.sh (for Linux). Bot configure file (by default is mybot.xml) defines the source list to start up the bot.
  3. Readme.txt contains useful information about what's included in the toolkit and some instructions.
  4. You need JDK (javac and jar) to compile Plugins
You can simply use free NovaBot hosting service. There is also a standalone Tomcat bot server there for download as well.

Now, let's look at a Hello Conversation:

< CML version="0.1" >
< Conv >
< Pattern > HELLO *< /Pattern >
< Answer > Hello there. < /Answer >
< /Conv >
< /CML >

Save this file as hello.cml in the unzipped toolkit directory. This document will assume this is your working directory by default. Open mybot.xml, change the value of "SourceList" to be hello.cml. Then start CindyGui in this directory. If anything is wrong, guilbotlog.txt will show you error's location. Also, guilbotlog.txt will show you exactly how each conversation is matched and executed.

If everything is right, you will have the bot prompt there. Type in "hello", the bot will respond you with "Hello there". guilbotlog.txt has the detailed logging information for the bot source loading and execution. You can change "LogLevel" setting in mybot.xml to have less / more logging. The log is your most powerful debugging tool for now. You can see exactly which line is
matched and executed.


Let's look at the tags used here.

CML

CML file must be enclosed in Tag CML. CML can take an optional attribute "version". Currently, Cindy interpreter only accepts version <=0.5

Conv


Conv is short for Conversation. It is the center piece of CML. It works somewhat like function or subroutine in a programming language. It is defined as one exchange of information between chat bot and a human user. Conversation may have an optional Name which can be used to reference to.

< Pattern> tag defines the string user input will be matched against. It is a case insensitive word by word matching. Wild card * can be used to match again zero or any number of words. The robot will try to match human input to the < Pattern> and start processing, possibly respond to human with the content defined in the < Answer> tag. You can have multiple Patterns in a conversation. Those Patterns will have a logical "OR" relation, which means if any Pattern element in this Conversation is matched, this Conversation is considered matched.

The < Answer> tag defines the bot response. In our example, the response is always "Hello there". < Answer> tag can contain plain text, C-Expression, other tags or even Action. So the response can be very flexible. You don't have to put all processing in the Answer element. All elements except Pattern and sub Conversation in a matched Conversation will be executed sequentially. However, only Answer and Ask can output to human user.

CML interpreter will always try to match other words first before it try to match *. So if you define another conversation like this:

< CML version="0.1" >
< Conv >
< Pattern > HELLO Cindy < /Pattern >
< Answer > Hey, I am glad you know my name.
< /Answer >
< /Conv >


If you add these lines to your hello.cml, and ask bot "Hello Cindy", bot will respond you with "Hey, I am glad you know my name." instead of "Hello there".

2 comments:

  1. It is beautiful worth sufficient for me. Personally, if all webmasters and bloggers made good content material as you did, the net will be a lot more helpful than ever before.
    AI Chatbot
    Chatbot Development
    RPA Bot
    Bank Chatbot
    Chatbots in Banking

    ReplyDelete
  2. I actually like what you’ve acquired here, certainly like what you are stating and the way in which you say it. You make it enjoyable and you still take care of to keep it sensible.

    Chatbot Company in Dubai
    Chatbot Companies in Dubai
    Chatbot Development
    AI Chatbot Development
    Chatbot Companies in UAE
    Chatbot Company in Chennai
    Chatbot Company in Mumbai
    Chatbot Company in Delhi
    Chatbot Development Companies

    ReplyDelete