Is it Live? Or is it Chatbot::Eliza?
When we were in college, my wife (then, girlfriend) had the best answering machine greeting message, ever. When people called her, the answering machine would answer, “Hello?” and wait. Invariably, the caller would start talking as though they had actually reached a live person. They'd be talking about last weeks assignments, or a party next week. Then the other shoe would drop. The answering machine would then continue, “Oh, I'm sorry. I'm not here at the moment. If you'd like to leave a message, please wait for the beep!” The caller would then have to start over, probably feeling a bit sheepish. Eventually, she changed her message to something more conventional, probably under threat of severe beatings from her friends and family. But before she changed it, she got to where she wouldn't even bother answering the phone if she was available; it was a lot of fun listening to people talk to a machine, thinking they were talking to a person.
I can relate. Ever since High School, I've wanted to write programs that acted like, or looked like real people. I remember playing with a program called Eliza when I was young and thinking how amazing it was that it worked as well as it id. The Eliza program would impersonate a Psychiatrist and attempt to “analyze” your “problem” by holding a natural language conversation with you. However, as soon as you realized that it was just matching simple patterns, it would mention something that you had said earlier, just to throw you for a loop. It was primitive, but effective.
When I was in college, I got heavily involved in playing in Multi-User Dungeons, or MUDs. These games were essentially text-based MMORPG's where people all over the world could talk to each other and explore places that had been created by other players. It was fun. Then came the 'bots. It became interesting, at least to me. The 'bots were programs just like Eliza. In fact, many of them used the same algorithm to appear as though they were another player in the game. Instead of a Psychiatrist, some of the 'bots posed as girlfriends, bar maids, mailmen, and even pets. But there was something new; they could respond to specific orders. For example, you could ask a 'bot how to get to a certain location in the MUD, or when a certain player was last on-line. You could even ask them about themselves. In addition to being fun and interesting, they became useful.
So a program that pretends to be human must be difficult to write, right? Well actually, it's embarrassingly simple, thanks to Perl's Chatbot::Eliza module. Let's take a look at a (very) trivial example:
#!/usr/bin/perl
use Chatbot::Eliza;
$bot = new Chatbot::Eliza("Jill", "");
$bot->command_interface();
That's right, 4 lines of code and no configuration needed! The module comes with a default database that allows it to carry on the tradition of the original Eliza program. Here is a sample of an interaction with “Jill.”
Jill: Please tell me what's been bothering you.
you: I'm bored.
Jill: Do you enjoy being bored?
you: No.
Jill: Does this make you feel unhappy?
you: Yes.
Jill: Please go on.
you: I want something to do.
Jill: Suppose you got something to do soon.
you: That would be great!
Jill: Tell me more about that.
you: I'm bored.
Jill: Is it because you are bored that you came to me?
you: yes.
Jill: I see.
Not bad for 4 lines of code, but our program isn't very flexible. For one thing, it's relegated to a command-line interface. Let's make a change to the program to demonstrate using the module from our own run-loop:
#!/usr/bin/perl
use Chatbot::Eliza;
$bot = new Chatbot::Eliza("Jill", "");
print $bot->{initial}->[0] . "\n";
$true++;
while ($true) {
print "You: ";
$message = <STDIN>;
$message = $bot->transform($message);
print "$message\n";
}
exit;
This program behaves almost exactly like the first program, but it demonstrates how the module could be integrated into a Jabber client, or an IRC client, or whatever. All you'd have to do is get a message from the user, pass it to the transform() method and send the result back to the user.
Still, a faux psychiatrist is kind of old hat; let's see how hard it is to change the program's “personality.” The module comes with a default data-set that implements the psychiatrist, but you can pass the name of a new database as the second parameter of the object's constructor. Depending on your political bent, this might resemble:
$bot = new Chatbot::Eliza("Sarah", "palin.txt");
or
$bot = new Chatbot::Eliza("Barak", "obama.txt");
Either of those could be a lot of fun, but I try to keep out of politics here. Anyway, now that we know how to load a different database, what does this database look like? Here is an excerpt from the default database:
key: remember 5
decomp: * i remember *
reasmb: Do you often think of (2) ?
reasmb: Does thinking of (2) bring anything else to mind ?
reasmb: What else do you recollect ?
reasmb: Why do you remember (2) just now ?
reasmb: What in the present situation reminds you of (2) ?
reasmb: What is the connection between me and (2) ?
reasmb: What else does (2) remind you of ?
The rest of the patterns resemble this one, so let's discuss what this does and how. The key: line introduces a keyword, “remember” and assigns it a ranking of 5. This represents a slight performance optimization. The module first scans the input message for key words. When a keyword is found, it's ranking is noted. The keyword with the highest rank wins and we move on the the “decomp” section. The decomp section is simply a pattern that we apply to an input sentence. The asterisks are wildcards and cause parts of the sentence to be stored for later substitution into the reply. If the decomp matches, the module will chose, randomly, from the list of reasmb choices. The reasmb, or reassembly patterns are what the module returns as a reply. Note that the numbers in parenthesis correspond to the asterisks in the decomp section. For example, (2) represents the second asterisk in the decomp pattern.
From here, it's easy to imagine creating a database that mimics almost any type of personality. But, we could do more. With just a little bit of work, we could slightly change the database format so that the returned message was a tab-delimited list. The first item on the list could be the return message, as before. The next item could be the name of a Perl function and parameters to evaluate. Such a pattern might look like:
key: like 5
decomp: * like you
reasmb: It's nice to hear that you like me <tab> karma(+1);
Then we could implement a subroutine called karma() that keeps track of how “nice” a person is. We would have to change our main loop so that when a given variable exceeds certain thresholds, a new database could be loaded resulting in “Jill” becoming increasingly “flirty,” or “witchy” depending on how she's spoken to. We could also implement functions that interact with the rest of the world. We could then ask “Jill” what the load average is on a given server, or we could ask her for the first link returned by Google for a given word or phrase. The sky is the limit.
Now I'm not seriously proposing an Eliza bot as the next generation of computer user interface. However, the Chatbot::Eliza Perl module is a fun toy that's easy to use and simple to expand and integrate. Have fun.
Mike Diehl is a freelance Computer Nerd specializing in Linux administration, programing, and VoIP. Mike lives in Albuquerque, NM. with his wife and 3 sons. He can be reached at mdiehl@diehlnet.com
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- New Products
- RSS Feeds
- Tech Tip: Really Simple HTTP Server with Python
- Epistle
52 min 12 sec ago - Automatically updating Guest Additions
2 hours 47 sec ago - I like your topic on android
2 hours 47 min ago - Reply to comment | Linux Journal
3 hours 8 min ago - This is the easiest tutorial
9 hours 22 min ago - Ahh, the Koolaid.
15 hours 1 min ago - git-annex assistant
21 hours 1 min ago - direct cable connection
21 hours 23 min ago - Agreed on AirDroid. With my
21 hours 33 min ago - I just learned this
21 hours 38 min ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.



Comments
who are you
who are you
Nice try
> He can be reached at mdiehl@diehlnet.com
Nice try. I'm sure anyone that tries to send an email to that email will get an Elizabot reply.
:-)
your wife
You are one very fortunate guy. What a great sense of humor! And after nearly 37 years of marriage, my wife and I can attest to just how important a good sense of humor is for maintaining an enjoyable, enduring relationship. I wish you and your wife many, many years of laughs together.
Thank you.
Thank you for the kind words. It's not just anyone who appreciates my "sense of humor."
Mike Diehl is a freelance Computer Nerd specializing in Linux administration, programing, and VoIP. Mike lives in Albuquerque, NM. with his wife and 3 sons. He can be reached at mdiehl@diehlnet.com
AI Chat
I remember a program written for BBS systems calles AI Chat. It took care of the annoying users who always wanted to chat with the sysop (as if the sysop had nothing better to do). It had a text list of responses to comments and questions that you could edit. This program fooled many users of a friends BBS , especially one bored kid that was always wanting to chat. My friend didn't mind the ocassional chat, but this kid was really annoying.
We customized the text list of responses to include phrases my friend used. It was quite a neat program.