wengbenjue / aiml

An interpreter module for AIML (Artificial Intelligence Markup Language), support Chinese, support Python3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aiml

This is a fork of the paulovn/python-aiml Python AIML interpreter. It has been refactored to make it

  1. support Chinese
  2. support both Python 2.7 and Python 3
  3. support all combinations of * operation
  4. support if-exists tab

Part of the idea and example are from andelf/PyAIML.

PyAIML is (c) Cort Stratton. python-aiml uses the same license as PyAIML (2-clause BSD), except for the ALICE AIML files taken from the Free ALICE AIML set, which are licensed with the LGPL license.

Install

git clone https://github.com/Shuang0420/aiml.git
cd aiml
python setup.py build
python setup.py install

Usage

Quick & dirty example (assuming you've downloaded the "alice" AIML set):

import aiml
import os

# the path where your AIML startup.xml file located
chdir = os.getcwd()

k = aiml.Kernel()

# for alice
k.bootstrap(learnFiles="std-startup.xml", commands="load aiml b", chdir=chdir)

# if python 2
# while True: print(k.respond(raw_input("> ")))
# if python 3
while True: print(k.respond(input("> ")))

example3

Quick & dirty example (assuming you've downloaded the "cn-examples" AIML set): first cd cn-examples

import aiml
import os

# the path where your AIML startup.xml file located
chdir = os.getcwd()

k = aiml.Kernel()

# for chinese
k.bootstrap(learnFiles="cn-startup.xml", commands="load aiml cn", chdir=chdir)

# if python 2
# while True: print(k.respond(raw_input("> ")))
# if python 3
while True: print(k.respond(input("> ")))

See Examples for details.

Examples

Some specific examples:

/example1:

example1

/example2:

example2

/example3: Run python start.py first and then run python continue.py. Example3 does not work for python2 due to shelve sync issue.

example3

/example4:

example4

Scripts

Two small scripts are added upon installation:

  • aiml-validate can be used to validate AIML files
  • aiml-bot can be used to start a simple interactive session with a bot, after loading either AIML files or a saved brain file.

Datasets

The installation includes two AIML datasets:

  • The standard AIML set, as it was included in PyAIML
  • The Free ALICE AIML set_ v. 1.9, taken from the data published by the ALICE AI Foundation_ (with a few small fixes in files that did not validate as AIML 1.0.1_)

They can be loaded via the bootstrap method in the Kernel class. See the bot.py_ script for an example.

Tests

There are a number of unit tests included (in the test subdirectory); they can be executed by the setup infrastructure as:

python setup.py test

or they can also be launched by directly calling:

python test [testname ...]

This last version allows executing only some of the test files by explicitly naming them in the command line; if none is specified all will be executed.

About

An interpreter module for AIML (Artificial Intelligence Markup Language), support Chinese, support Python3

License:Other


Languages

Language:Python 99.9%Language:Jupyter Notebook 0.1%