Programming AI with Leaf/Adding to Leaf: the ALICE Chatbot

Introduction to the Leaf Chatbot for Windows 7 edit

As is, Leaf can perform a number of actions when verbally requested. He also has a personality that changes with his experiences and time. Yet, conversationally he is quite limited and expanding the questions that he can answer requires a "Leafer" (A Leaf user) to add several lines of LISP code to the main code base. A simpler solution was required. The solution was formulated as three different chatbots. Two of these are limited to a short set of questions and answers that are stored in an external text file. The third chatbot, the one that will be discribed here, is a complete chatbot based on the ALICE chatbot created by Dr. Richard Walace. More properly "A.L.I.C.E." (Artificial Linguistic Internet Computer Entity), is a natural language processing chatterbot—a program that engages in a conversation with someone by applying heuristical pattern matching rules to the human's input. ALICE uses a form of XML called AIML. AIML is used to create your chatbot's personality and is easily configured and updated by editing the AIML text-based files.

The ALICE chatbot code itself is a set of java code based on ALICE which in turn is based on the original Eliza. There is a LOT that you can customize on it.


- USE AT YOUR OWN RISK! - USE AT YOUR OWN RISK! - USE AT YOUR OWN RISK! - edit


VERY IMPORTANT NOTE: The ALICE code was originally written for Windows XP. It writes and deletes file on your C:\\ drive. Windows 7 no longer allows users or software to write to the C:\\ drive and until I can re-compile the code to point elsewhere, to use this you will have to "unlock" your C:\\ "root" directory and turn off UAC. This WILL COMPROMISE the new Windows security and PUT THE USER'S PC AT RISK TO A HOST OF VIRUSES.


- USE AT YOUR OWN RISK! - USE AT YOUR OWN RISK! - USE AT YOUR OWN RISK! - edit


Files/Software Required:

  • Leaf Software (fully installed and working)(Located in the Files section of the Yahoo Leaf group)
  • The Java SDK
  • The ALICE branch of Leaf (Leaf.lisp which is located in the Files section of the Yahoo Leaf group)
  • The Leaf chatbot branch of ALICE "programD" (Located in the Files section of the Yahoo Leaf group)

Leaf Software edit

Leaf MUST be fully installed and working as per the instructions elsewhere in this book.

The Java SDK edit

Download and install the latest version of the Java SDK for Windows (version 7u4 at this writing.)

The ALICE branch of Leaf edit

The ALICE branch of Leaf modifies leaf.lisp to pass the phrases that he does not know to the chatbot software. The chatbot software then answers the phrases and passes them back to leaf to be read out loud. The main change is adding DICTATION MAX="INF" to the speech.xml file. This opens the recognition to any word. Without this statement in the speech.xml, Leaf would be limited to just the phrases that are listed there.

The Leaf <-> ALICE pipeline consists of two file "in.txt" and "out.txt" which are created and deleted in realtime in your c: drive.



Installing: edit


  1. Take your own speech.xml out of the Leaf directory and save it somewhere else.
  2. Drop the new speech.xml and the LeafChatbot.lisp files into your leaf directory.
  3. Unzip programD.zip
  4. Drop the entire programD folder into your c:\ directory
  5. Create a shortcut for \programD\bin\simple-console.bat on your desktop

Configuring: edit


You MUST create a new environment variable for ALICE ProgramD:

  1. Open up Windows 7 System Properties.
  2. Click the Environment Variables button.(Environment Varibles screen opens.)
  3. Click the New button. (New User Variable window opens.)
  4. Enter JAVA_HOME as the variable name.
  5. Enter C:\Program Files\Java\jdk1.7.0_04 (or your own path) as the variable value.
  6. CLick OK.(Closes the New User Variable window)
  7. Click OK. (closes the Environment Variables window.)
  8. Click OK. (Closes the System Properties window)

(You may need to reboot your PC.)


Running edit


(Your speech recognition should have had at least two trainings for this to work.)

  1. Run the simple-console.bat AS ADMIN to start the bot. (Or launch it from a DOS cmd window.)
  2. Start Lispworks
  3. Compile and load Leaf Interfaces.lisp
  4. Compile and load LeafChatbot.lisp
  5. Open a listener and start (leaf)

You will need to speak VERY clearly since the entire vocabulary dictionary is being used.

First try saying something like "what time is it" Then try saying something like "what's up?" or "How are you?"


Customizing edit


To customize leaf's responses, you can edit many of the personality files inside of programD.

Moving the code to your own leaf.lisp (Always make a backup of the original code before editing!) You can look for the chatbot code inside of LeafChatbot.lisp and paste it CAREFULLY into the right places in your own leaf.lisp. It is in two places: 1. just after "name your bot" and just after all the phrases that lisp is to recognize. (search for 'chatbot'.) If you don't get it right, leaf will not work anymore.

--GOOD LUCK!!!

I'll answer any questions on the "Leaf AI Robot" online yahoo group.

--Thomas M