RS 1.20 SVN Trunk - Topic inclusions/inheritence, Syntax checking, more|Kirsle|casey@cuvou.net|1247701114|Kirsle|xx|0|72.37.252.50|In the current version of bleeding-edge RiveScript available in the [url=http://svn.kirsle.net/repos/RiveScript-perl/trunk]subversion repository[/url], the following new things have been implemented:<br /><br />[list]<br />[*]Topics can now &quot;include&quot; other topics, in addition to &quot;inheriting&quot; them<br />[*]A new RS doc has been added to the standard brain, which features a simple text-based roleplaying game demonstration, which uses both includes and inherits with its topics.<br />[*]The working draft was fixed, version declaration lines in RiveScript are in the &quot;! version = 2.00&quot; format, not &quot;! version 2.00&quot;<br />[*]Syntax checking has been added to RiveScript, causing a fatal error when an invalid line of RiveScript code has been read.<br />[/list]<br /><br />The biggest new change is the way topics can inherit replies from other topics. Consider:<br /><br />[quote]&gt; topic alpha [b]includes[/b] beta [b]inherits[/b] gamma[/quote]<br /><br />First of all, the previous implementation of the &quot;inherits&quot; keyword was done wrong: the old behavior of &quot;inherits&quot; is now called &quot;includes&quot; in this release. The &quot;inherits&quot; keyword now has a different purpose. I'll cover both of their uses here:<br /><br />[b]includes[/b]<br /><br />When a topic &quot;includes&quot; another topic, it basically makes the triggers from the included topic available under the current (source) topic. So if topic A has 10 triggers and topic B has 5 triggers, and A includes B, then A effectively has 15 triggers -- including the ones provided by B -- and then those 15 triggers are sorted as one group, as though all 15 of them were from A to begin with.<br /><br />This means that if A has some long triggers and some short triggers, and B has some long triggers and some medium-sized triggers, the sort list will cause A and B's triggers to be mixed together by length with A's short triggers at the end, because A's short triggers are shorter than B's triggers.<br /><br />Here's an example:<br /><br />[code] // This is in the default &quot;random&quot; topic and catches all non-matching<br /> // triggers.<br /> + *<br /> - I'm afraid I don't know how to reply to that!<br /><br /> &gt; topic alpha<br />  + alpha trigger<br />  - Alpha's response.<br /> &lt; topic<br /><br /> &gt; topic beta<br />  + beta trigger<br />  - Beta's response.<br /> &lt;<br /><br /> &gt; topic gamma<br />  + gamma trigger<br />  - Gamma's response.<br /> &lt; topic<br /><br /> &gt; topic delta<br />  + delta trigger<br />  - Delta's response.<br /><br />  + *<br />  - You can't access any other triggers! Haha!<br /> &lt; topic[/code]<br /><br />[code] &gt; topic ab includes alpha<br />  + hello bot<br />  - Hello human!<br /> &lt; topic<br /><br /> // Matching order:<br /> alpha trigger<br /> hello bot[/code]<br /><br />Alpha's trigger got sorted above ab's trigger because it was longer.<br /><br />The behavior of &quot;includes&quot; in this release is the same as the behavior of &quot;inherits&quot; from before.<br /><br />[b]inherits[/b]<br /><br />Now, inherits allows topics to actually [i]override[/i] another topic. What this means is that all of the triggers in the source topic (and topics included into the source topic) are all sorted amongst themselves, [i]AND THEN[/i] triggers from the inherited topic are sorted and placed at the end. Using our topics above, here's an example of inheritence:<br /><br />[code] &gt; topic abc inherits alpha beta<br />  + how are you<br />  - Good, how are you?<br /><br />  + *<br />  - You matched my star trigger!<br /> &lt; topic<br /><br /> // Matching order:<br /> how are you<br /> *<br /> alpha trigger<br /> beta trigger[/code]<br /><br />In this case, the two triggers from our &quot;abc&quot; topic are sorted amongst themselves, where * always goes at the very end of the list, [i]and then[/i] the combined triggers of alpha and beta are sorted as one group and placed at the end. In this case, &quot;alpha trigger&quot; and &quot;beta trigger&quot; are unmatchable because of that * there.<br /><br />Here is an example that combines includes and inherits:<br /><br />[code] &gt; topic abc includes alpha beta delta inherits gamma<br />  + how are you<br />  - Good, how are you?<br /> &lt; topic<br /><br /> // Matching order:<br /> how are you<br /> alpha trigger<br /> delta trigger<br /> beta trigger<br /> *<br /> gamma trigger[/code]<br /><br />In this case all the triggers from abc, alpha, beta, and delta are included together and sorted as a group, and then the gamma triggers are sorted (there's only one so not much sorting is necessary) and added at the end.<br /><br />So [b]includes[/b] includes triggers that were defined under a different topic into the current topic, and [b]inherits[/b] causes all of the triggers in the source topic (and included topics) to have higher matching priority than anything in the inherited topic.<br /><br />Note that, at this time, the ordering of the topic line doesn't matter. For example, &quot;topic alpha inherits beta includes gamma&quot; does [b]NOT[/b] mean that beta+gamma are combined and inherited by alpha. It still means that alpha+gamma are combined together and they inherit beta.<br /><br />Anyway, this update required some major architectural change on the source code, so I need people to test the copy from subversion and see if they find any problems with it before I release it to CPAN.<br /><br />The release comes with a new RiveScript doc with its standard brain, rpg.rs, which is an example of a text-based roleplaying game in RiveScript, which makes use of both includes and inherits. The game source is full of comments to clarify why includes is used instead of inherits and how the topics are pieced together.<br /><br />[b]Source of rpg.rs (to see how includes/inherits works):[/b] http://svn.kirsle.net/repos/RiveScript-perl/trunk/lib/RiveScript/demo/rpg.rs<br /><br />[b]Check out RiveScript 1.20 from Trunk:[/b]<br /><br />On a Unix-like system with subversion, run this command:<br /><br />[code]svn checkout http://svn.kirsle.net/repos/RiveScript-perl/trunk RiveScript-perl[/code]<br /><br />On Windows you can simply navigate to http://svn.kirsle.net/repos/RiveScript-perl/trunk/ - you'll want to download RiveScript.pm from the lib/ folder and load it into your Perl scripts to test it.<br /><br />Try to test the following things:<br /><br />* If you already have a bot or RiveScript documents, make sure everything still works the same with the new version<br />* Try experimenting with the new capabilities of the includes/inherits with topics||||
