My idea here was to write an Eliza style bot that added new keyword/response pairs to itself. Its not perfect but it is still kinda a cool hack. You can see a working example that is suppose to act like Gir from invader zim here. Here is the code:
#!/usr/bin/perl use CGI qw( header param ); use Chatbot::Eliza; sub parse { my $data = shift; $data =~ tr/A-Z/a-z/; my @junk = qw( am is are was were be been have has had do does did can + should may might must shall should will would to of the i ); my $junk; foreach $junk(@junk) { $data =~ s/($junk | $junk)//g; } $data =~ s/(\.|!)//g; return $data; } print header; print "<TITLE> chatbot </title>\n"; print '<body bgcolor="black" background="line.gif" alink="#ff9900" lin +k="#ff9900" vlink="#ff9900" text="#ff9900">'; my $gir = new Chatbot::Eliza "Gir", "brain"; my $babble = param("babble"); my $orig = $babble; if ($babble =~ /\?|you/) { 1; } else { my $jist = parse($babble); my @words = split(/ /, $jist); open(BRAIN,">>brain"); my $word; foreach $word(@words) { my $num = int(rand 10); my $mem = $orig; $mem =~ tr/A-Z/a-z/; $mem =~ s/my /your /g; $mem =~ s/i /you /g; $mem =~ s/mine /yours /g; print BRAIN "key: $word $num\n"; print BRAIN " decomp: *\n"; print BRAIN " reasmb: $mem\n"; } } my $response = $gir->transform( $orig ); print "Bot: $response\n"; print <<HTML; <FORM METHOD="GET" ACTION="http://yoursite.com/url/goes/here.cgi"> You:<INPUT TYPE="text" NAME="babble" SIZE="30"> <INPUT TYPE="submit" value="talk"></form> HTML print '</body>';
You need a Eliza file to start with I used this for my Gir bot:
initial: How do you do. Please tell me your problem. initial: Hello, I am a computer program. initial: Please tell me what's been bothering you. initial: Is something troubling you? final: Goodbye. It was nice talking to you. final: Goodbye. I hope you found this session helpful. final: I think you should talk to a REAL analyst. Ciao! final: Life is tough. Hang in there! quit: bye quit: goodbye quit: done quit: exit quit: quit pre: dont don't pre: cant can't pre: wont won't pre: recollect remember pre: recall remember pre: dreamt dreamed pre: dreams dream pre: maybe perhaps pre: certainly yes pre: machine computer pre: machines computer pre: computers computer post: am are post: your my post: yours mine pre: were was post: me you pre: you're you are pre: i'm i am post: myself yourself post: yourself myself post: i you post: you me post: my your post: me you post: i'm you are pre: same alike pre: identical alike pre: equivalent alike synon: belief feel think believe wish synon: family mother mom father dad sister brother wife children child synon: desire want need synon: sad unhappy depressed sick synon: happy elated glad better synon: cannot can't synon: everyone everybody nobody noone synon: be am is are was key: xnone -1 decomp: * reasmb: burrrrrrito! reasmb: hehehe reasmb: I'm gonna sing the doom song now! reasmb: I need TACO! key: sorry 0 decomp: * reasmb: its oooookaaaaay key: apologise 0 decomp: * reasmb: goto sorry


"Sanity is the playground of the unimaginative" -Unknown

In reply to Learning Chatterbot by beretboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.