AI Zone Admin Forum Add your forum

NEWS: survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

perl -> what if the rs files of the loadDirectory changes?


use strict;
use warnings;
use RiveScript;
my $rs = RiveScript->new();


while (1) {
print "You> ";
chomp(my $message = <STDIN>);
if ($message eq "/quit") {
  my $reply = $rs->reply(“user”, $message);
  print “Bot> $reply\n”;

Hi Guys…

In the obove example:
What would happen if the rs files are changed?.
How can we take care of the changes without restarting perl script.
Sorry for the silly question!..


  [ # 1 ]

Unique to the Perl version only, you can call loadDirectory() again to reload the bot.

# call reloadBot(BOT) anytime you want to reload the bots replies from disk.
sub reloadBot {
($rs) = @_;


What happens is: any already-existing +Trigger that was loaded the first time, will have its data updated in-place. New triggers that weren’t there the first time will be loaded as normal.

One caveat though, if you’re _removing_ any RiveScript code (delete a trigger or replies or *Conditions etc), this in-place reload will be a bit ‘messy’ and not remove the old data. When RiveScript sees a +Trigger it sets some state variables (counters for the number of -Reply’s or *Conditions, etc) and as it reads the replies it will fill in the data, but if the “new” counters don’t match or exceed the old ones, the “extra” replies left from the old load will still be there in memory.

Adding or changing existing lines of code should always be safe though.

Why only the Perl version? because the Perl version stores +Trigger patterns as the keys to a hashmap. Same key = it puts the data in the same place during a reload. This storage model came with some limitations, though (duplicate +Triggers for the same %Previous don’t work correctly for example), and so the other versions of RiveScript (JS, Go, Python and Java) have switched to storing triggers on an array type. On these versions, reloading the bot in this way is not supported because it will just duplicate all the triggers! And most likely, your new replies won’t be used because the old trigger already matches the old replies.

For those versions of RiveScript the only way to reload is to completely destroy and re-make your RiveScript bot object.

# reload for Python: you have to delete and reinit the bot
class MyBot:
def __init__(self):
"""Your initial setup function"""

def setup_bot(self): RiveScript()"./brain")

def reload_bot(self):
"Reload the bot's brain from disk"""

  login or register to react