1、python3安装pip install pip install python-aiml
2、将alice文件复制到工作区


3、源码如下:
import aiml
# Create the kernel and learn AIML files
kernel = aiml.Kernel()
kernel.learn("std-startup.xml")
kernel.respond("load aiml b")
# Press CTRL-C to break this loop
while True:
print(kernel.respond(input("Enter your message >> ")))
std-startup.xml
<aiml version="1.0.1" encoding="UTF-8">
<!-- std-startup.xml -->
<!-- Category is an atomic AIML unit -->
<category>
<!-- Pattern to match in user input -->
<!-- If user enters "LOAD AIML B" -->
<pattern>LOAD AIML B</pattern>
<!-- Template is the response to the pattern -->
<!-- This learn an aiml file -->
<template>
<learn>basic_chat.aiml</learn>
<!-- You can add more aiml files here -->
<!--<learn>more_aiml.aiml</learn>-->
</template>
</category>
</aiml>
basic_chat.aiml
<aiml version="1.0.1" encoding="UTF-8">
<!-- basic_chat.aiml -->
<category>
<pattern>HELLO</pattern>
<template>
Well, hello!
</template>
</category>
<category>
<pattern>WHAT ARE YOU</pattern>
<template>
I'm a bot, silly!
</template>
</category>
<category>
<pattern>你好</pattern>
<template>
I'm a bot, silly!你好
</template>
</category>
<category>
<pattern>2</pattern>
<template>
111111I'm a bot, silly!你好
</template>
</category>
</aiml>
运行结果:

该博客介绍了如何使用python的python-aiml库搭建一个全匹配的机器人对话系统。首先,通过pip安装python-aiml,接着将必要的 alice 文件复制到工作目录,然后提供源码包括 testb.py, std-startup.xml 和 basic_chat.aiml。运行这些文件后,即可得到对话结果。"
82720836,5792330,C++面试:解析指针数组与数组指针的差异,"['C++', '数据类型', '指针', '数组', '面试']
3万+

被折叠的 条评论
为什么被折叠?



