Hey guys, RiveScript creator here! It seems some versions of RiveScript are buggy around the !person handler and fixes are welcome on GitHub.
The JavaScript version exhibits this bug: https://play.rivescript.com/s/YRI1pXSoER
Me> say I am to you what you are to me
Bot> Um... "I are to you what I am to me"
But the Python and Go versions handle this a bit better:
You> say I am to you what you are to me
RiveScript> Um... "you are to I what I am to me"
Note: these are using the default !person substitutions in the example brain that comes with RiveScript, adding some tweaks to it produces a more grammatically correct result:
! version = 2.0
// Person substitutions
! person i am = you are
! person you are = I am
! person i'm = you're
! person you're = I'm
! person my = your
! person your = my
! person you = me
! person i = you
! person me = you
+ say *
- Um... "<person>"
You> say you are to me what I am to you
Bot> Um... "I am to you what you are to me"
I think what goes wrong with the JavaScript version is that parts of the sentence are being substituted twice. In the Python, Go and Perl versions I use "placeholder" sequences when it runs the substitutions so that it doesn't double-substitute, then it replaces those placeholders back at the end with the final result. The JS version gets the most contributions on GitHub and it's been refactored a few times so my original logic was changed and is today a bit buggy.
Examples where it was handled better:
* Python: https://github.com/aichaos/rivescript-python/blob/a28deb389d88c2a3f988dd93e15a04c0e536704e/rivescript/brain.py#L807-L842
* Perl: https://github.com/aichaos/rivescript-perl/blob/2b43e04e0750e6ed0661566e568754bf5c95bf05/lib/RiveScript.pm#L3284-L3315
Also, cool to see RiveScript is still relevant in 2022!
#! /usr/bin/env perl
my $sentence = "i am to you what you are to me.";
for ($sentence) {
s/i am/YOU ARE/g;
s/you are/I AM/g;
s/i'm/YOU'RE/g;
s/you're/I'M/g;
s/my/YOUR/g;
s/your/MY/g;
s/you/ME/g;
s/i/YOU/g;
s/me/YOU/g
}
print $sentence;
Save as: transform.pl
Runs with: perl transform.pl
(OUTPUT)
YOU ARE to ME what I AM to YOU.
NOTE:
sudo chmod +x transform.pl
TODO:
Convert $sentence to sentence case in another pass.
« Edit Notes: Updated code »