Welcome, Guest. Please Login or Register
RiveScript HQ
 
  HomeHelpSearchLoginRegister  
 
Pages: 1
Send Topic Print
learn and forget capabilities (Read 860 times)
yvesago
Newbie
*
Offline

I Love RiveScript!

Posts: 4

learn and forget capabilities
06/02/08 at 23:53:54
 
a simple way to add learn and forget capabilities on one keyword

Code:
+ {weight=10000}learn * *
- learning <star1>. <call>learn <star1> <star2></call>

> object learn perl
  my ($rs,$args,@args2) = @_;

  return if ( length $args <= 2) ;

  my $msg = join(" ",@args2);
  my $cmd = "
+ [\*] $args [\*]
- $msg
";

  $rs->stream ($cmd);
  $rs->sortReplies();

  return "success! $args learned.";
< object

+ {weight=10000}forget *
- <call>forget <star></call>

> object forget perl
  my ($rs,$args) = @_;

  return if ( length $args <= 2) ;

  my $cmd = "
+ [\*] $args [\*]
";

  $rs->stream ($cmd);

  $rs->sortReplies();

  return "success! $args forgeted.";

< object
 

Back to top
 
 
View Profile   IP Logged
Kirsle
Administrator
*****
Offline

I Love YaBB 2!

Posts: 60
Los Angeles
Gender: male
Re: learn and forget capabilities
Reply #1 - 06/19/08 at 18:16:55
 
Cool idea, but your learning pattern is ambiguous:

Code:
+ learn * * 



What does each * match? if you say "learn hello bot hello human", <star1> could be "hello" and <star2> "bot hello human", or <star1> could be "hello bot hello" and <star2> be "human", or any other combination.

Here's a better way of doing it, and getting it to save the file for later on so when the bot's reloaded it'll remember it still.

Code:
+ {weight=100}learn *
- <set learning=<star>>I will learn a response to "<star>". Type the response now.{topic=learning}

> topic learning
   + *
   - Learning reply... <call>learn <id>::<get learning>::<sentence></call>{topic=random}
< topic

> object learn perl
   my ($rs,@args) = @_;
   my $in = join(" ",@args);
   my ($id,$pattern,$reply) = split(/::/, $in, 3);

   my $code = "// Taught by: $id\n"
      . "+ $pattern\n"
      . "- $reply\n\n";

   # Append it to contrib.rs so it'll be reloaded later on.
   open (APPEND, ">>./rscripteg/contrib.rs");
   print APPEND $code;
   close (APPEND);

   # Stream it in.
   $rs->stream ($code);
   $rs->sortReplies();

   return "Success!";
< object 



Having it forget a reply is a bit tricky though. Just having a +trigger with no -response isn't that great (you'll end up with "ERR: No Reply Found", because it found a match to the trigger but no associated reply. You'd have to get into the module's internals to really delete a trigger...

Code:
+ {weight=100}forget *
- Forgetting that trigger... <call>forget <get topic> <star></call>

> object forget perl
   my ($rs,$topic,@args) = @_;
   my $trig = join(" ",@args);

   if (exists $rs->{topics}->{$topic}->{$trig}) {
      delete $rs->{topics}->{$topic}->{$trig};
      $rs->sortReplies();
      return "forgotten!";
   }
   else {
      return "I never knew that trigger...";
   }
<  



That would only delete it from memory but not erase it from contrib.rs, but if ya really wanted to you could have it read the file, delete those lines, and save it again. Smiley

Anyway, here's my example in action:

Code:
[kirsle@fonality RiveScript-1.15]$ ./rsdemo
Welcome to the Perl RiveScript Interpreter. This script is a demonstration
of RiveScript. The bot's replies are taken from the files in the
'rscripteg' directory, which by default are based on some of Eliza's
triggers and responses.

You're now chatting with the RiveScript bot. Why not say hello? When
you get tired of this, type "quit" to exit this demonstration.

You> learn all your base are belong to us
Bot> I will learn a response to "all your base are belong to us". Type the response now.
You> we get signal
Bot> Learning reply... Success!
You> k
Bot> Does talking about this bother you?
You> all your base are belong to us
Bot> We get signal
You> ^C

[kirsle@fonality RiveScript-1.15]$ ./rsdemo
Welcome to the Perl RiveScript Interpreter. This script is a demonstration
of RiveScript. The bot's replies are taken from the files in the
'rscripteg' directory, which by default are based on some of Eliza's
triggers and responses.

You're now chatting with the RiveScript bot. Why not say hello? When
you get tired of this, type "quit" to exit this demonstration.

You> all your base are belong to us
Bot> We get signal
You> forget all your base are belong to us
Bot> Forgetting that trigger... forgotten!
You> all your base are belong to us
Bot> Did you think they might not be belong to us?
You>  

Back to top
 
 
View Profile WWW 147180999 Kirsle   IP Logged
echoline
Newbie
*
Offline

I Love RiveScript!

Posts: 3

Re: learn and forget capabilities
Reply #2 - 01/20/10 at 18:15:23
 
i ported badanswer.aiml to rs.  it seems to be working ok.
Back to top
 
View Profile   IP Logged
Pages: 1
Send Topic Print