Python AIML Build a chat robot instance

Source: Internet
Author: User
AIML, full name is artificial Intelligence Markup Language (AI Markup Language), is an XML language for creating natural language software proxies, which is made by Richard Wallace and the free software community around the world were invented from 1995 to 2002, and through this article we introduce how Python uses AIML to build chat bots, and friends need to learn together.

With Python's AIML package, we can easily implement AI chat bots. AIML, full name is artificial Intelligence Markup Language (AI Markup Language), is an XML language for creating natural language software proxies, which is made by Richard Wallace and the free software community around the world were invented from 1995 to 2002.

What is AIML?

Aiml was invented by Richard Wallace. He designed a robot called A.L.I.C.E. (Artificial linguistics Internet Computer entity artificial language network computer entities), and won a number of AI awards. Interestingly, one of the Turing tests was looking for such artificial intelligence: humans and robots could use a text interface for a few minutes to see if the robot would be considered human. AIML is an XML format that defines rules for matching patterns and determining responses.

AIML's official website: ALICE.

This article briefly describes how to use Python to write a simple chat robot.

1. Install the Python AIML Library

Pip Install AIML

2. Get Alice Resources

After the Python AIML installation is complete, the LIB/SITE-PACKAGES/AIML subdirectory will be available under the Python installation directory and the directory will be copied to the workspace.
or download Alice Brain:aiml-en-us-foundation-alice.v1-9.zip on Google code

3. Python under load Alice

After getting Alice resources, you can load Alice brain directly from the Python AIML library:


Import Aimlos.chdir ('./res/alice ') #切换工作目录到alice文件夹下, depending on the case alice = Aiml. Kernel () Alice.learn ("Startup.xml") Alice.respond (' LOAD Alice ')

Note that you need to switch the working directory to Alice under load.

4. Chat with Alice

After loading, you can chat with Alice, and you only need to call the respond interface at a time:

Alice.respond (' Hello ') #这里的hello即为发给机器人的信息

5. Build a chat robot website with tornado

Using tornado, it is easy to build a Web interface chat robot. The specific code can be linked under this link in: Web interface of the chat robot.
After downloading this code, run main.py directly, then you can access the URL and the chat robot through the browser, the URL is similar to the Http://localhost/aiml?req=hello (req parameter is the information sent to the robot).

Note To run this code, you need to install the Python AIML and tornado libraries.

This web interface has been built on lwons.com and can be accessed by Http://lwons.com/aiml?req=hello for testing.

6. Build a chat robot subscription number

The previous step of the Web interface can be easily transformed into a subscription number, the effect of the implementation can be added after the subscription number Curiousguys send a message directly. If you need a subscription number code, you can private me.

Subscription number effect:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.