#!/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 " chatbot \n"; print ''; 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 < You: HTML print ''; #### 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