The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

RiveScript - Rendering Intelligence Very Easily

SYNOPSIS

use RiveScript;

# Create a new RiveScript interpreter.
my $rs = new RiveScript;

# Load a directory of replies.
$rs->loadDirectory ("./replies");

# Load another file.
$rs->loadFile ("./more_replies.rive");

# Stream in some RiveScript code.
$rs->stream (q~
    + hello bot
    - Hello, human.
~);

# Sort all the loaded replies.
$rs->sortReplies;

# Chat with the bot.
while (1) {
    print "You> ";
    chomp (my $msg = <STDIN>);
    my $reply = $rs->reply ('localuser',$msg);
    print "Bot> $reply\n";
}

DESCRIPTION

RiveScript is a simple trigger/response language primarily used for the creation of chatting robots. It's designed to have an easy-to-learn syntax but provide a lot of power and flexibility. For more information, visit http://www.rivescript.com/

METHODS

GENERAL

LOADING AND PARSING

CONFIGURATION

INTERACTION

RIVESCRIPT

This interpreter tries its best to follow RiveScript standards. Currently it supports RiveScript 2.0 documents. A current copy of the RiveScript working draft is included with this package: see RiveScript::WD.

UTF-8 SUPPORT

Version 1.29+ adds experimental support for UTF-8 in RiveScript. It is not enabled by default. Enable it by passing a true value for the utf8 option in the constructor, or by using the --utf8 argument to the rivescript application.

By default (without UTF-8 mode on), triggers may only contain basic ASCII characters (no foreign characters), and the user's message is stripped of all characters except letters and spaces. This means that, for example, you can't capture a user's e-mail address in a RiveScript reply, because of the @ and . characters.

When UTF-8 mode is enabled, these restrictions are lifted. Triggers are only limited to not contain certain metacharacters like the backslash, and the user's message is only stripped of backslashes and HTML angled brackets (to prevent obvious XSS if you use RiveScript in a web application). The <star> tags in RiveScript will capture the user's "raw" input, so you can write replies to get the user's e-mail address or store foreign characters in their name.

CONSTANTS

This module can export some constants.

use RiveScript qw(:standard);

These constants include:

SEE ALSO

RiveScript::WD - A current snapshot of the Working Draft that defines the standards of RiveScript.

http://www.rivescript.com/ - The official homepage of RiveScript.

CHANGES

1.34  Feb 26 2014
- Update README.md to include module documentation for github.
- Fixes to META.yml

1.32  Feb 24 2014
- Maintenance release to fix some errors per the CPANTS.
- Add license to Makefile.PL
- Make Makefile.PL not executable
- Make version numbers consistent

1.30  Nov 25 2013
- Added "TCP Mode" to the `rivescript` command so that it can listen on a
  socket instead of using standard input and output.
- Added a "--data" option to the `rivescript` command for providing JSON
  input as a command line argument instead of standard input.
- Added experimental UTF-8 support.
- Bugfix: don't use hacky ROT13-encoded placeholders for message
  substitutions... use a null character method instead. ;)
- Make .rive the default preferred file extension for RiveScript documents
  instead of .rs (which conflicts with the Rust programming language).
  Backwards compatibility remains to load .rs files, though.

1.28  Aug 14 2012
- FIXED: Typos in RiveScript::WD (Bug #77618)
- Added constants RS_ERR_MATCH and RS_ERR_REPLY.

1.26  May 29 2012
- Added EXE_FILES to Makefile.PL so the rivescript utility installs
  correctly.

1.24  May 15 2012
- Fixed: having a single-line, multiline comment, e.g. /* ... */
- Fixed: you can use <input> and <reply> in triggers now, instead of only
  <input1>-<input9> and <reply1>-<reply9>
- When a trigger consists of nothing but multiple wildcard symbols, sort
  the trigger by length, this way you can have '* * * * *' type triggers
  still work correctly (each <star> tag would get one word, with the final
  <star> collecting the remainder).
- Backported new feature from Python lib: you can now use <bot> and <env>
  to SET variables (eg. <bot mood=happy>). The {!...} tag is deprecated.
- New feature: deparse() will return a Perl data structure representing all
  of the RiveScript code parsed by the module so far. This way you can build
  a user interface for editing replies without requiring a user to edit the
  code directly.
- New method: write() will use deparse() to write a RiveScript document using
  all of the in-memory triggers/responses/etc.
- Cleaned up the POD documentation, put POD code along side the Perl functions
  it documents, removed useless bloat from the docs.
- POD documentation now only shows recent changes. For older changes, see the
  "CHANGES" file in the distribution.
- Removed the `rsup` script from the distribution (it upgrades RiveScript 1.x
  code to 2.x; there probably isn't any 1.x code out in the wild anyway).

1.22  Sep 22 2011
- Cleaned up the documentation of RiveScript; moved the JavaScript object
  example to a separate document in the `docs' directory.
- Obsoleted the `rsdemo` command that used to ship with the distribution. In
  its place is `rivescript`, which can also be used non-interactively so that a
  third party, non-Perl application could still make use of RiveScript.
- RiveScript.pm is now dual licensed. It uses the GPLv2 for open source
  applications as before, but you can contact the author for details if you
  want to use RiveScript.pm in a closed source commercial application.

1.20  Jul 30 2009
- Added automatic syntax checking when parsing RiveScript code. Also added
  'strict mode' - if true (default), a syntax error is a fatal error. If false,
  a syntax error is a warning, and RiveScript aborts processing the file any
  further.
- Changed the behavior of "inherits" a bit: a new type has been added called
  "includes" which does what the old "inherits" does (mixes the trigger list
  of both topics together into the same pool). The new "inherits" option though
  causes the trigger list from the source topic to be higher in matching priority
  than the trigger list of the inherited topic.
- Moving to a new versioning scheme: development releases will have odd
  version numbers, stable (CPAN) versions will have even numbers.
- Fixed the Eliza brain; in many places a <star2> was used when there was only one
  star in the trigger. Fixes lots of issues with Eliza.
- Bugfix: recursion depth limits weren't taken into account when the {@} tag
  was responsible for a redirection. Fixed.
- Bugfix: there was a problem in the regular expression that counts real words
  while sorting triggers, so that triggers with *'s in them weren't sorted
  properly and would therefore cause matching issues.
- Bugfix: when the internal _getreply is called because of a recursive
  redirection (@, {@}), the %previous tags should be ignored. They weren't.
  since "lastreply" is always the same no matter how deeply recursive _getreply
  is going, it could result in some infinite recursion in rare cases. Fixed.
- Bugfix: using a reserved name as a global variable wasn't working properly
  and would crash RiveScript. Fixed.

1.19  Apr 12 2009
- Added support for defining custom object handlers for non-Perl programming
  languages.
- All the methods like setGlobal, setVariable, setUservar, etc. will now
  accept undef or "<undef>" as values - this will delete the variables.
- There are no reserved global variable names anymore. Now, if a variable name
  would conflict with a reserved name, it is put into a "protected" space
  elsewhere in the object. Still take note of which names are reserved though.

1.18  Dec 31 2008
- Added support for topics to inherit their triggers from other topics.
  e.g. > topic alpha inherits beta
- Fixed some bugs related to !array with ^continue's, and expanded its
  functionality therein.
- Updated the getUservars() function to optionally be able to get just a specific
  variable from the user's data. Added getUservar() as a grammatically correct
  alias to this new functionality.
- Added the functions freezeUservars() and thawUservars() to back up and
  restore a user's variables.
- Added the function lastMatch(), which returns the text of the trigger that
  matched the user's last message.
- The # command for RiveScript comments has been deprecated in revision 7 of
  the RiveScript Working Draft. The Perl module will now emit warnings each
  time the # comments are processed.
- Modified a couple of triggers in the default Eliza brain to improve matching
  issues therein.
- +Triggers can contain user <get> tags now.
- Updated the RiveScript Working Draft.

AUTHOR

Noah Petherbridge, http://www.kirsle.net

KEYWORDS

bot, chatbot, chatterbot, chatter bot, reply, replies, script, aiml, alpha

COPYRIGHT AND LICENSE

The Perl RiveScript interpreter is dual licensed as of version 1.22. For open source applications the module is using the GNU General Public License. If you'd like to use the RiveScript module in a closed source or commercial application, contact the author for more information.

RiveScript - Rendering Intelligence Very Easily
Copyright (C) 2014 Noah Petherbridge

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA