User Control Panel
Advertisements

HELP US, HELP YOU!

AIML::Simple

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Modules & Add-ons
View unanswered posts
Author Message
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Mon Apr 25, 2005 9:12 pm    Post subject: Reply with quote

This is a module I wrote using XML::Simple, it's for simple processing of AIML documents without having to worry about those other AIML:: modules (which always like to assume you're running a 100% Alice bot, when sometimes you only want the AIML parsing part of it).

So, here it is!

This is an alpha release and it doesn't quite support ALL the AIML that exists, right now in version 0.01 it supports:
Code:
- Simple pattern/template responses<br />- Patterns with <random> responses<br />- Templates with <srai><br />- Wildcard matching (haven't done much with <star/> though).


Example:
Code:
#!/usr/bin/perl -w<br /><br />use strict;<br />use warnings;<br />use lib "./lib";<br />use AIML::Simple;<br /><br /># Create and load AIML data.<br />my $aiml = new AIML::Simple (debug => 1, level => 1);<br />my ($result,$verb) = $aiml->load ('test.aiml');<br />print $verb if $result == 0;<br /><br />while (1) {<br />     print " User> ";<br />     my $msg = <STDIN>;<br />     chomp $msg;<br /><br />     my $reply = $aiml->reply ('localhost', $msg);<br />     print "Alice> $reply\n\n";<br />}

Code:
<?xml version="1.0" encoding="ISO-8859-1"?><br /><aiml><br />     <category><br />          <pattern>*</pattern><br />          <template>I'm afraid I don't know how to reply to that!</template><br />     </category><br /><br />     <category><br />          <pattern>WHAT IS YOUR NAME</pattern><br />          <template>My name is Alice.</template><br />     </category><br /><br />     <category><br />          <pattern>HELLO</pattern><br />          <template>Hello to you too.</template><br />     </category><br /><br />     <category><br />          <pattern>HI</pattern><br />          <template><srai>HELLO</srai></template><br />     </category><br /><br />     <category><br />          <pattern>TEST</pattern><br />          <template><br />               <random><br />                    <li>Random 1</li><br />                    <li>Random 2</li><br />                    <li>Random 3</li><br />               </random><br />          </template><br />     </category><br /></aiml>


I also tested it with a simplified version of Wallace.aiml from the annotated Alice AIML.

METHODS
Quote:
new (DEBUG?)

Creates a new AIML::Simple instance. Optionally can pass in parameters:

Code:
debug => 1|0<br />level => 1|0 # Debug level, 1 = print EVERYTHING, 0 = print only useful stuff


debug (MSG), verbose (MSG)

Called by the module itself for debugging and verbose messages. (level = 1)

loadDirectory (DIRECTORY[, FILE_TYPES])

Loads a complete directory of files. Optionally pass in FILE_TYPES, but it assumes
"aiml" as a type.

load (FILEPATH)

Loads a single AIML document. loadDirectory calls this method for each file it finds
anyway, so it's recommended to use loadDirectory if you have a folder full of AIML
documents.

sortReplies

After loading replies, call sortReplies to sort them (normal replies first, wildcard
carriers second). If you load new replies after sorting, you'll have to resort them
before they will be available.

reply (USER_ID, MESSAGE[, STAR_REPLY])

Returns a reply. If there's an error, it will return a reply beginning with
"AIML::Simple::error" and then the text of the error. USER_ID and MESSAGE are self
explanatory. STAR_REPLY, if 1, will allow the module to return a reply if the trigger
was just a wildcard (this isn't recommended because a single wildcard can match anything.
This is called from within the module when it can't find a better reply).

Returns $reply (the reply), and $sub (a hashref containing the other tags found in the
reply, for example, . Your application can deal with these how it wants to).

replyLoop (ARGUMENTS)

Same as reply, but starts and maintains a loop counter. It will keep trying to get a reply,
but if it fails after 30 tries it will finally give up and return an "AIML::Simple::error // Deep recursion"
error. This would happen, for example, if the module can't find a good reply and is trying to find
the * wildcard pattern which doesn't exist or was improperly formatted, or if there exists an SRAI
to a pattern which does not exist.


Like I said, this is an alpha release. It needs lots of work. If you're an AIML fan, feel free to modify the code, the majority of the parsing work is done and it would just take some amount of modifying to make it do whatever else you think AIML should be capable of.

The package is attached.

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Modules & Add-ons All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group