Git Product home page Git Product logo

pyaiml_extended's Introduction

PyAIML_Extended

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.

Usage:

Example AIML file...

(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>

Example Python Plugin...

(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!!!"

Plugin directory structure...

  • 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   

Loading the plugins and corresponding AIML files...

  • 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('> '))

pyaiml_extended's People

Contributors

splitter avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.