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).
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/