Chapter 12. Chatbot::Eliza

John Nolan

Of all the chatterbots—programs that converse with humans—Eliza is the most famous. The original Eliza was written by Professor Joseph Weizenbaum of MIT and described in the Communications of the ACM in 1967 (Vol. 10, No. 8). This program is older than I am, and yet remains fascinating to this day. It’s one of the all-time classic programs in computer science. Eliza pretends to be a Rogerian psychiatrist; whatever the human says, it replies—usually with a question—in an attempt to encourage the patient to elaborate.

The Eliza algorithm has been cloned dozens of times in all kinds of programming languages, including Fortran, Basic, Pascal, C, Java, and JavaScript. The first Eliza was written in a Lisp-like language called MAD-Slip, way back in pre-Unix days. (Eliza is named after Eliza Doolittle, the cockney-speaking woman taught to speak proper English in G.B. Shaw’s book Pygmalion.)

While taking a course in Natural Language Processing, I was surprised to find that much of the research in the field still uses Lisp. Lisp is a fine language, but Perl can do anything Lisp can do, and Perl source code is much easier to read. I searched the Web for Eliza clones, but I couldn’t find any written in Perl. So I wrote one.

The Chatbot::Eliza module is a faithful clone of Weizenbaum’s Eliza algorithm. It encapsulates Eliza’s behavior within an object.

You can install Chatbot::Eliza just like any other Perl module. Once installed, this little bit of code is ...

Get Games, Diversions & Perl Culture now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.