Introduction to RiveScript
What is RiveScript?RiveScript is a text-based scripting language for giving chatterbots the ability to respond to messages from humans using natural language.
What is a Chatterbot?A chatterbot is a software program that chats with humans using natural language. Chatterbots commonly do this by signing on to instant messengers and chat rooms and chatting with humans. Usually they wait for the human to initiate contact and respond to their message.
What does RiveScript look like?RiveScript is text-based -- this means you can write and edit RiveScript code using nothing more than a simple text editor. Notepad on Windows can be used, or any other editor you have available.
RiveScript code is processed one line at a time by the RiveScript Interpreter -- the software that knows how to execute RiveScript code. Each line begins with a command character and then extra data that means something to the interpreter based on that command. A plus symbol (+) tells the interpreter how to match a message given by the human, and a minus symbol (-) tells it how it should respond to that message.
In the following example, if the human says "
hello bot", the bot
would reply with "
+ hello bot - Hello human!
What is the history behind RiveScript? Why does it exist?This section is optional reading; you can skip past it if you don't care to know all the details behind RiveScript's history.
RiveScript was written by Noah Petherbridge (Kirsle) in 2004 to fill a void in the development of chatterbots in the Perl programming language. There simply weren't any chatterbot response languages implemented in Perl, and the other major language of AIML (Artificial Intelligence Markup Language) has too complex of a format to be efficiently implemented in Perl.
Kirsle began developing chatterbots with the free service at RunABot.com and then moved to running a bot on AliceBot software -- both RunABot and Alicebots used the Artificial Intelligence Markup Language (AIML), an XML-based language for mapping human input to bot's responses. However, none of the AIML-based bots were capable of connecting to MSN Messenger (now Windows Live Messenger), and after a quick Google search he found WiredBots.com (now defunct), which provided barebones bot templates to sign on to MSN and also AOL Instant Messenger.
The templates really were bare-bones -- all they did was sign on a bot, and the bot would send a completely random quote in response to anything you say to it.
The only Perl AliceBot was called Program V, and Kirsle tried hacking it apart to get its AIML parsing code out of it so he could use it in his own bots. Alicebot programs are generally intended to be complete chatterbots - so in the case of Program V, it was exceedingly difficult to disconnect the AIML parsing code from the code that, say, parses config files or handles storing of user data. Program V's code was entirely integrated into itself and it was difficult to isolate the AIML code from it.
At the same time, building code from scratch that parses AIML is also a very difficult task. AIML is an XML-based language, but its syntax is difficult to parse because of canonicalism -- tags can be parents of or children of other tags, and tags can be stacked in a nearly infinite combination. It's worse than HTML to parse in Perl.
Failing to parse AIML, and failing to create a new XML-based language that resembles AIML for the same reason, Kirsle decided to just create a new language, and make it very easy for Perl -- or any other programming language, for that matter -- to parse. So, RiveScript was born.
About this tutorialThis is an interactive tutorial. As you complete each section you'll be able to try out what you've learned live on the web. Each section will be accompanied by a collection of template RiveScript scripts that can be selected at any time from the web-based demo tool, or you can write your own code and test it live.
See the Appendix section for links to learn how to build your own offline RiveScript interpreter in Perl by using the RiveScript Perl library.