PyAIML with added <plugin> tag to implement simple plugin system. Also added support for the caret(^), a wildcard(similar to *) that matches 0 or more instead of 1 or more as existing wildcards do.
The new <plugin> tag functions almost exactly as the <template> tag with the added ability for response to be sent to a custom python plugin before final response is returned.
(SideNote: All plugins must contain AIML files.)
- Every <plugin> tag must have a 'name' attribute corresponding to the plugins Python Class name
<?xml version="1.0" encoding="UTF-8"?> <aiml> <category> <pattern>WHO IS THE REAL IRON MAN</pattern> <plugin name="ironman"> Data you want sent to plugin if pattern matched </plugin> </category> </aiml>And seeing that the <plugin> tag is similar in function to the <template> you could do something like this...
<?xml version="1.0" encoding="UTF-8"?> <aiml> <category> <pattern>WHO IS THE REAL IRON MAN</pattern> <plugin name="ironman"> Data you want sent to plugin if pattern matched </plugin> </category> <category> <pattern>WHO IS IRON MAN</pattern> <template> <srai>WHO IS THE REAL IRON MAN</srai> </template> </category> <category> <pattern>DO YOU KNOW WHO IRON MAN REALLY IS</pattern> <template> <srai>WHO IS THE REAL IRON MAN</srai> </template> </category> </aiml>Or...
<?xml version="1.0" encoding="UTF-8"?> <aiml> <category> <pattern>Weather forecast for *</pattern> <plugin name="weather"> <star/> </plugin> </category> </aiml>(SideNote: Not all plugins need python code, without it the plugin just adds a new AIML file to learn)
- Every Plugin must implement a 'getResponse' method that returns a string that will be the final response. There is a base class to inherit from to enforce this.
- The class name must correspond to the plugin name in AIML file
from aiml import BasePlugin class ironman(BasePlugin.BasePlugin): def getResponse(self, args): return "Tony Stark is the Real Iron Man!!!"- Plugins should each be in individual directories
- Individual plugin directory names should correspond to plugin class name
- Individual plugin file names should correspond to plugin class name
- Plugins should be in a parent plugin directory(no naming enforement for parent directory)
|-- Plugins/ |-- ironman/ |-- ironman.aiml |-- ironman.py - After creating an AIML Kernel instance call the loadPlugins method passing in Path to the Plugins directory
import aiml bot = aiml.Kernel(); bot.loadPlugins("./Plugins"); while 1: print bot.respond(raw_input('> '))