Artificial Intelligence Scripting Language

Perl for RiveScript-Java!

Posted by Kirsle on Monday, Oct 25 2010 @ 12:19 PM
I've just checked in an update to the RiveScript-java code:

It supports Perl objects now!

So you can use your existing RiveScript Perl objects with the Java library now. Example:

+ encode * in md5
- "<star> in MD5 is: <call>md5 <star></call>

> object md5 perl
   my $rs = shift;

   use Digest::MD5 qw(md5_hex);
   return md5_hex(join(" ", @_));
< object

How does it work? There's a Perl script names "rsp4j.pl" that the Java library calls on. Java sends a JSON-encoded data structure to the Perl script containing the user's ID, message, user variables, and the source code to the Perl object. The Perl script loads the RiveScript Perl module and uses it to evaluate a response to the user. It then outputs a new JSON structure containing the user's reply and their new user variables (in case the Perl object called any setUservars methods on the $rs object).

The 0.02 version of rivescript-java has the Perl support. You can see its usage in the RSBot.java example script, or more generally here's all you need to do to get Perl support:

RiveScript rs = new RiveScript();
rs.setHandler("perl", new com.rivescript.lang.Perl(rs, "/path/to/rsp4j.pl");

Categories: General , Perl , Java

[ Kirsle's Blog ]

Comments

There are 0 comments on this page.

Leave a Comment

Your name:
Message:
You can use emoticons in your comment (opens in a new window).

If you can see this, don't touch the following fields.