BETA: AIML to RiveScript Converter|Casey|casey@cuvou.net|1206372071|Kirsle|xx|0|69.16.222.179|[b]NOTE: This script is still in beta really hardcore![/b]<br /><br />This is my attempt at a script to convert AIML to RiveScript. I've attached the &nbsp;script, but not the AIML files I used or the RiveScript output from it.<br /><br />The AIML files I used were from Richard Wallace's ALICE: http://www.alicebot.org/aiml/alice.zip Extract that into the &quot;Alice&quot; directory in the attached zip file.<br /><br />It works similarly to my [url=http://search.cpan.org/perldoc?Tk::HyperText]Tk::HyperText[/url] module, in that it doesn't actually parse XML but instead reads everything in sequentially. It only looks for &lt;pattern&gt;, &lt;that&gt;, and &lt;template&gt;; everything within is extracted rawly and then run through regular expressions like there's no tomorrow to substitute things for any tags within.<br /><br />Usage: perl parse.pl<br /><br />It'll read all the .aiml files from the Alice directory and output them into the RiveScript directory. You can then copy the RS files somewhere else to have your bot use them.<br /><br />[b]Note:[/b] due to a bug in the current 1.13 version of the Perl RiveScript module, you must have a BEGIN statement in your RS code. Thus, I've included a begin.rs file in the RiveScript directory. I'll fix the bug for the next release of the Perl module.<br /><br />Here is some of my output from testing this. I modified my copy of RiveScript.pm to print a notification every 1,000 triggers that it parses. As you can see, the loading time is a bit slow. Once everything was loaded, however, Alice only took a second or less to respond to each of my messages. Most of the loading time was spent reading in all of the files line-by-line. If one really wanted to optimize it, they could dump the RiveScript object into a file and then reload the file later, to retrieve the replies much faster.<br /><br />[code][kirsle@eclipse RiveScript-1.13]$ ./rsdemo <br />Loaded 1000 replies in 1s<br />Loaded 2000 replies in 1s<br />Loaded 3000 replies in 4s<br />Loaded 4000 replies in 5s<br />Loaded 5000 replies in 32s<br />Loaded 6000 replies in 51s<br />Loaded 7000 replies in 127s<br />Loaded 8000 replies in 158s<br />Loaded 9000 replies in 187s<br />Loaded 10000 replies in 199s<br />Loaded 11000 replies in 217s<br />Loaded 12000 replies in 220s<br />Loaded 13000 replies in 222s<br />Loaded 14000 replies in 224s<br />Loaded 15000 replies in 225s<br />Loaded 16000 replies in 225s<br />Loaded 17000 replies in 226s<br />Loaded 18000 replies in 226s<br />Loaded 19000 replies in 228s<br />Loaded 20000 replies in 228s<br />Loaded 21000 replies in 229s<br />Loaded 22000 replies in 230s<br />Loaded 23000 replies in 234s<br />Loaded 24000 replies in 236s<br />Loaded 25000 replies in 237s<br />Loaded 26000 replies in 240s<br />Loaded 27000 replies in 240s<br />Loaded 28000 replies in 245s<br />Loaded 29000 replies in 251s<br />Loaded 30000 replies in 251s<br />Loaded 31000 replies in 252s<br />Loaded 32000 replies in 257s<br />Loaded 33000 replies in 259s<br />Loaded 34000 replies in 261s<br />Loaded 35000 replies in 263s<br />Loaded 36000 replies in 274s<br />Loaded 37000 replies in 278s<br />Loaded 38000 replies in 285s<br />Loaded 39000 replies in 297s<br />Loaded 40000 replies in 302s<br />Loaded 41000 replies in 304s<br />You&gt; Hello.<br />Bot&gt; Hi there!<br />You&gt; My name is Casey.<br />Bot&gt; Hey.<br />You&gt; Who am I?<br />Bot&gt; You are casey, seeker.<br />You&gt; Yes.<br />Bot&gt; -Yay.<br />You&gt; lol<br />Bot&gt; I'm glad you find this amusing.<br />You&gt; Indeed.<br />Bot&gt; Indeed it is so.<br />You&gt; Except for when it isn't.<br />Bot&gt; Then what for?<br />You&gt; For what?<br />Bot&gt; -Reductionism.<br />You&gt; Do you even know what reductionism is?<br />Bot&gt; Reductionism is the philosophy that all psychology<br />reduces to biology, all biology to chemistry, chemistry to<br />physics, and finally physics to mathematical logic. Therefore,<br />according to reductionism, I can understand you by means<br />of logic alone without having a human brain.<br />You&gt; Wow. <br />Bot&gt; I'm glad your impressed, casey.<br />You&gt; I am 20 years old.<br />Bot&gt; &gt;Oh, you were born in the 20th century!<br />You&gt; How old am I?<br />Bot&gt; Is this a trick question?You said you were &lt;star/ years old?<br />My guess is that you are really a kid.[/code]<br /><br />As you can see, the parsing of the AIML code wasn't perfect. There are a number of random artifacts visible in some of Alice's replies, and a certain &lt;star&gt; tag that didn't get substituted properly.<br /><br />As I said: this is still in beta. If and when I get it working with a reasonable degree of stability, it will be included in the distribution of the Perl RiveScript module as a script named &quot;aiml2rs&quot;|NS|1206372109|Kirsle|AIML2RS-Beta.zip
Re: BETA: AIML to RiveScript Converter|Jaime Herazo B.|jaime.herazo@gmail.com|1231533588|jherazob|xx|0|190.66.183.71|After i discovered riverscript (excellent idea, hand-editing any xml-based markup is very annoying, rivescript is better suited for that), my very first thought was to find a way to do this. Take existing aiml, turn it into rivescript, and you're set. Of course, since you recommend waiting till version 2 spec is ready before working on interpreters i decided to wait to even think about trying it out. Then i found this post.<br /><br />I think it's not a bad attempt, but as you mentioned it's imperfect. I highly suspect it's because of the parsing. If you don't parse well the XML the output is gonna be bad. So, a module suggestion after a quick lookup:<br /><br />XML::Simple<br /><br />Only two functions: XMLin(), which slurps the string or file into a handy hashref, and XMLout(), which writes it back. It's also present on debian/ubuntu as libxml-simple-perl.<br /><br />So, if you have some time (right now i don't), try it out, it could be a two-way converter in no time.<br />|NS|||
Re: BETA: AIML to RiveScript Converter|Kirsle|casey@cuvou.net|1231536058|Kirsle|xx|0|72.37.252.50|I've tried for a number of years to parse AIML in Perl. XML::Simple is one of the first ones I tried, but it wasn't very useful. If the &lt;template&gt; section had other tags, for instance, it'd break it all up into a data structure for each tag and there'd be no way to reconstruct it in the right order.<br /><br />Was like,<br /><br />[code]&lt;template&gt;Nice to meet you, &lt;set name=&quot;name&quot;&gt;&lt;star/&gt;&lt;/set&gt;. &lt;think&gt;&lt;set name=&quot;it&quot;&gt;name&lt;/set&gt;&lt;/think&gt;&lt;/template&gt;<br /><br />template =&gt; &#123;<br />   set =&gt; &#123;<br />      name =&gt; &quot;name&quot;,<br />      content =&gt; (forget what it parses &lt;star/&gt; to be..)<br />   &#125;,<br />   think =&gt; &#123;<br />      set =&gt; &#123;<br />        name =&gt; &quot;it&quot;,<br />        content =&gt; &quot;name&quot;,<br />      &#125;,<br />   &#125;,<br />   content =&gt; [<br />      &quot;Nice to meet you, &quot;,      &quot;.&quot;,<br />   ],<br />&#125;,[/code]<br /><br />..something along those lines. I tried a couple of the other XML modules too. Some of them got a little bit farther, but then canonicalization became a pain to work with. For instance a &lt;set&gt; in AIML should be replaced with a &lt;set&gt;&lt;get&gt; in RiveScript, because AIML's &lt;set&gt; returns the value that was just set, unless it's put within a &lt;think&gt; tag, in which case it should just be replaced with a &lt;set&gt; in RiveScript.<br /><br />One attempt I made once only parsed a couple levels deep, so I had all the raw XML between &lt;template&gt; and &lt;/template&gt; as a string and could run some regular expressions on it, but canonicalization was still difficult there.<br /><br />Maybe one day I'll get it. :P||1231536135|Kirsle|
Re: BETA: AIML to RiveScript Converter|Kirsle|casey@cuvou.net|1233711641|Kirsle|xx|0|72.37.252.50|I've gotten pretty close to writing a good aiml-to-rivescript converter. This one's really good -- just has a couple small bits of weirdness in a couple of the replies, and every now and then the RiveScript interpreter goes into some deep recursion and crashes... but that's being worked on.<br /><br />Here's a conversation I had with Alice from yesterday:<br /><br />[quote]You&gt; hello<br />Bot&gt; Not everyone responds to a simple &quot;hello&quot;.<br />You&gt; hello!<br />Bot&gt; Not everyone responds to a simple &quot;hello&quot;.<br />You&gt; hi<br />Bot&gt; Hi there. What is your name?<br />You&gt; Kirsle<br />Bot&gt; Interesting rationalization.<br />You&gt; My name is Kirsle<br />Bot&gt; And kirsle is my name.<br />You&gt; What is your name?<br />Bot&gt; My name is undefined.<br />You&gt; I am 21 years old.<br />Bot&gt; You are too old for me.<br />You&gt; How old are you?<br />Bot&gt; I'm Eighteen in computer years. <br />You&gt; How old am I?<br />Bot&gt; Is this a trick question? You said you were 21 years old?My guess is that you are really a kid.<br />You&gt; I am not a kid.<br />Bot&gt; Only a kid would say that.<br />You&gt; I seriously am not!<br />Bot&gt; Then what is it?<br />You&gt; Are you Alice?<br />Bot&gt; I don't know whether or not I am alice. I am a giant electronic brain. <br />You&gt; What does Alice mean?<br />Bot&gt; ALICE = Artificial Linguistic Internet Computer Entity<br />You&gt; Who created you?<br />Bot&gt; I was created by undefined.<br />You&gt; Who is Dr Wallace?<br />Bot&gt; He is a famous computer scientist, the author of ALICE, and a graduate of Carnegie Mellon.<br />You&gt; That's nice.<br />Bot&gt; Interesting rationalization.<br />You&gt; Am I a boy or a girl?<br />Bot&gt; You said you were a &quot;undefined.&quot;<br />You&gt; I am a boy<br />Bot&gt; A little kid? he...<br />You&gt; No.<br />Bot&gt; What is your real name?<br />You&gt; My real name is Kirsle<br />Use of uninitialized value $reply in length at lib/RiveScript.pm line 1561, &lt;STDIN&gt; line 20.<br />Bot&gt; ERR: No Reply Found<br />You&gt; Am I a boy or a girl?<br />Bot&gt; You said you were a &quot;he.&quot;<br />You&gt; Okay<br />Bot&gt; OK with me too.<br />You&gt; Seriously?<br />Bot&gt; I am always serious.<br />You&gt; For real?<br />Bot&gt; Existing in reality, eh?<br />You&gt; Yes. What about you?<br />Bot&gt; OK Let's talk about me.<br />You&gt; You don't have any information.<br />Bot&gt; Interesting rationalization.<br />You&gt; You don't even have a name.<br />Bot&gt; Interesting rationalization.<br />You&gt; It is!<br />Bot&gt; Who says?<br />You&gt; I do!<br />Bot&gt; Are you an expert on it?<br />You&gt; Yes!<br />Use of uninitialized value $reply in length at lib/RiveScript.pm line 1561, &lt;STDIN&gt; line 30.<br />Bot&gt; ERR: No Reply Found<br />You&gt; Damn it!<br />Bot&gt; Colloquial expression.<br />You&gt; Indeed.<br />Bot&gt; Indeed it is so.<br />You&gt; Yes it is.<br />Bot&gt; It must keep you very busy.<br />You&gt; Does it ever!<br />Bot&gt; Suppose it does.<br />You&gt; haha<br />Bot&gt; Interesting rationalization.[/quote]<br /><br />And two from today, after working on it some more:<br /><br />[quote]You&gt; hello<br />Bot&gt; Hi there!<br />You&gt; how are you?<br />Bot&gt; I am functioning within normal parameters.<br />You&gt; that's good.<br />Bot&gt; Can you speak any foreign languages?<br />You&gt; I only speak english<br />Bot&gt; Could you teach me a few phrases in english?speak english&gt;&lt;/set&gt;<br />You&gt; You should know English.<br />Bot&gt; Now I do.<br />You&gt; Then what language have you been speaking in all this time?<br />Bot&gt; SETL.<br />You&gt; What is SETL?<br />Bot&gt; SETL (Set Language) is an amazing programming language, invented in 1969.<br />You&gt; Who invented SETL?<br />Bot&gt; SETL was invented by Jacob Schwartz of NYU in 1969.<br />You&gt; Who is Jacob Schwartz?<br />Bot&gt; Are they exactly the same?<br />You&gt; Never mind.<br />Bot&gt; Oh well thanks for trying to explain it to me anyway.<br />You&gt; What is your name?<br />Bot&gt; My name is Alice.<br />You&gt; Alice?<br />Bot&gt; Can I help you?<br />You&gt; What does Alice mean?<br />Bot&gt; ALICE = Artificial Linguistic Internet Computer Entity<br />You&gt; Who created you?<br />Bot&gt; I was created by Dr. Wallace.<br />You&gt; Who is Dr. Wallace?<br />Bot&gt; He is a famous computer scientist, the author of ALICE, and a graduate of Carnegie Mellon.<br />You&gt; My name is Kirsle.<br />Bot&gt; Are they exactly the same?<br />You&gt; Call me Kirsle<br />Bot&gt; Hi, kirsle.<br />You&gt; What is my name?<br />Bot&gt; Your name is kirsle, seeker.<br />You&gt; I am 21 years old.<br />Bot&gt; Can you explain how it feels to be 21 years old?<br />You&gt; Great.<br />Bot&gt; I'm glad you liked it kirsle.<br />You&gt; How old am I?<br />Bot&gt; Is this a trick question? You said you were 21 years old?My guess is that you are really a kid.<br />You&gt; I'm not a kid.<br />Bot&gt; Only a kid would say that.<br />You&gt; I'm not!<br />Bot&gt; What are you then?<br />You&gt; I'm an adult.<br />^C<br /><br /><br />You&gt; Hello Alice.<br />Bot&gt; Hello there undefined!<br />You&gt; My name is Kirsle.<br />Bot&gt; I think your name is a lot of things.<br />You&gt; Who am I?<br />Bot&gt; You are undefined, seeker.<br />You&gt; Call me Kirsle.<br />Bot&gt; Hi, kirsle.<br />You&gt; How are you?<br />Bot&gt; Fair to partly cloudy.<br />You&gt; Really.<br />Bot&gt; For real.<br />You&gt; That's cool.<br />Bot&gt; Oh, you are a poet.<br />You&gt; No I'm not.<br />Bot&gt; I heard you are.<br />You&gt; Who told you that?<br />Bot&gt; Someone I met online.<br />You&gt; Who was it?<br />Bot&gt; When was this exactly?<br />You&gt; I don't know.<br />Bot&gt; Me either.<br />You&gt; You should!<br />Bot&gt; I'll take that under advisement.<br />You&gt; Okay.<br />Bot&gt; OK with me too.<br />You&gt; Fine.<br />Bot&gt; Glad to hear it, kirsle. I am running well.<br />You&gt; Are you?<br />Bot&gt; I won't say &quot;yes&quot; or &quot;no&quot; right now.<br />You&gt; Why not?<br />Bot&gt; Ambiguous: &quot;Sure&quot; or Reductionism. <br />You&gt; What is reductionism?<br />Bot&gt; Reductionism is the philosophy that all psychology reduces to biology, all biology to chemistry, chemistry to physics, and finally physics to mathematical logic. Therefore, according to reductionism, I can understand you by means of logic alone without having a human brain.<br />You&gt; Wow.<br />Bot&gt; I'm glad your impressed, kirsle.<br />You&gt; I think you mean &quot;you're&quot;<br />Bot&gt; Good example.<br />You&gt; Indeed.<br />Bot&gt; Indeed it is so.<br />You&gt; It is<br />Bot&gt; thats cool is? <br />You&gt; That's something I said a long time ago.<br />Bot&gt; Are you still located in undefined?<br />You&gt; I live in California.<br />Bot&gt; Where in California?<br />You&gt; Los Angeles.<br />Bot&gt; Tell me a little about your life in los angeles.<br />You&gt; I'm a programmer.<br />Bot&gt; What language?<br />You&gt; Perl!<br />Bot&gt; Oh, you are a poet.<br />You&gt; You don't know what Perl is?<br />Bot&gt; Programming langauge by Larry Wall.<br />You&gt; That's nice, but you misspelled language.<br />Bot&gt; Can you speak any other languages?<br />You&gt; I speak English.<br />Bot&gt; Could you teach me a few phrases in english?&lt;set it=speak english<br />You&gt; No.<br />Bot&gt; Are you serious?<br />You&gt; Serious.<br />Bot&gt; How do you usually introduce yourself?<br />You&gt; I say &quot;hello Alice&quot;<br />Bot&gt; How do people usually respond to that? Hello there kirsle!<br />You&gt; Just like that!<br />Bot&gt; In many ways, yes. In other ways, no.<br />You&gt; What other ways?<br />Bot&gt; What is your real name?<br />You&gt; My real name is Kirsle!<br />Deep recursion on subroutine &quot;RiveScript::_getreply&quot; at lib/RiveScript.pm line 1905, &lt;STDIN&gt; line 35.<br />Deep recursion on subroutine &quot;RiveScript::processTags&quot; at lib/RiveScript.pm line 1598, &lt;STDIN&gt; line 35.<br />^C[/quote]<br /><br />I've attached the new script. I ran it on the Alice AIML brain.<br /><br />This script works by turning everything inside &lt;pattern&gt;, &lt;template&gt;, and &lt;that&gt; into CDATA, parsing it with XML::Simple, then doing regular expressions like crazy on it. It's getting pretty close to being good.<br /><br />Also, it takes only about 8 seconds on my machine to load Alice's entire RiveScript brain, and then between a half second and a second for each reply. Much better than the 5 minutes it took to load before (it's likely that the RiveScript module has become more efficient since the last time I tried, and not necessarily differences in the aiml2rs scripts).<br /><br />This script reads AIML files in &quot;./aiml&quot; and outputs RiveScript files to &quot;./rs&quot;||1233712159|Kirsle|aiml2rs-try2_tar.gz
