Giter Site home page Giter Site logo

aiml.js's Introduction

AIML.js

AIML Interpreter written in node.js

AIMLInterpreter is a module that allows you to parse AIML files and to find the correct answer to a given message.

Installation

$ npm install aimlinterpreter

Dependencies
fs
dom-js

Description
With new AIMLInterpreter(botAttributes) one can create a new interpreter object. botAttributes is an JSON-Object that can contain attributes of the bot one wants to use in AIML files, e.g. ({name: "Bot", age:"42"}).
This object has a function called loadAIMLFilesIntoArray(fileArray) which receives an array of AIML files. This function loads the AIML file into memory.
Furthermore, the object has a function called findAnswerInLoadedAIMLFiles(clientInput, cb) which receives a message and a callback. The callback is called when an answer was found. The callback of findAnswerInLoadedAIMLFiles should look like this: callback(result, wildCardArray, input). Result is the answer from the AIML file and wildCardArray stores the values of all wildcardInputs passed previously from the client. The original input which triggered the answer is given back via input.

Example:

AIMLInterpreter = require('./AIMLInterpreter');
var aimlInterpreter = new AIMLInterpreter({name:'WireInterpreter', age:'42'});
aimlInterpreter.loadAIMLFilesIntoArray(['./test.aiml.xml']);

var callback = function(answer, wildCardArray, input){ console.log(answer + ' | ' + wildCardArray + ' | ' + input); };

aimlInterpreter.findAnswerInLoadedAIMLFiles('What is your name?', callback); aimlInterpreter.findAnswerInLoadedAIMLFiles('My name is Ben.', callback); aimlInterpreter.findAnswerInLoadedAIMLFiles('What is my name?', callback);


Supported AIML tags:
<bot name="NAME"/>
<get name="NAME"/>
<set name="NAME">TEXT</set>
<random><li>A</li><li>B</li><li>C</li></random>
<srai>PATTERN TEXT</srai>
<sr/>
<star/>
<that>TEXT</that>
<condition name="NAME" value="VALUE">TEXT</condition>
<condition><li name="NAME" value="VALUE">TEXT</li><li name="NAME" value="VALUE">TEXT</li><li>TEXT</li></condition>
<condition name="NAME"><li value="VALUE">TEXT</li><li value="VALUE">TEXT</li><li>TEXT</li></condition>

<think><set name="NAME">TEXT</set></think> <anyElement/><random><li>A</li><li>B</li><li>C</li></random><anyElement/> <random><li><think><set name="NAME">TEXT</set></think></li><li>B</li></random> <random><li><srai>PATTERN TEXT</srai></li><li>B</li></random> <condition name="NAME" value="VALUE"><srai>PATTERN TEXT</srai></condition> <condition><li name="NAME" value="VALUE"><srai>PATTERN TEXT</srai></li><li name="NAME" value="VALUE">TEXT</li></condition> <condition name="NAME"><li value="VALUE"><srai>PATTERN TEXT</srai></li><li value="VALUE">TEXT</li></condition>


Contributors
Special thanks go to Sergio Rodriguez (https://github.com/sergiorodez), who contributed to the interpreter and enhanced its functionalities

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.