没有合适的资源?快使用搜索试试~ 我知道了~
今天午休的时候,无意之中看了一篇博客,名字叫Python实现机器人,感觉挺有的意思的。 于是用其写了一个简单的Python聊天,源码如下所示: # -*- coding: utf-8 -*- import aiml import sys import os def get_module_dir(name): print(module, sys.modules[name]) path = getattr(sys.modules[name], '__file__', None) print(path) if not path: raise AttributeError('modul
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/14840446/bg1.jpg)
Python如何实现机器人聊天如何实现机器人聊天
今天午休的时候,无意之中看了一篇博客,名字叫Python实现机器人,感觉挺有的意思的。
于是用其写了一个简单的Python聊天,源码如下所示:
# -*- coding: utf-8 -*-
import aiml
import sys
import os
def get_module_dir(name):
print("module", sys.modules[name])
path = getattr(sys.modules[name], '__file__', None)
print(path)
if not path:
raise AttributeError('module %s has not attribute __file__' % name)
return os.path.dirname(os.path.abspath(path))
alice_path = get_module_dir('aiml') + '\botdata\alice'
os.chdir(alice_path) # 切换到语料库所在工作目录
alice = aiml.Kernel() # 创建机器人alice对象
alice.learn("startup.xml") # 加载...\botdata\alice\startup.xml
alice.respond('LOAD ALICE') # 加载...\botdata\alice目录下的语料库
while True:
message = input("Enter your message >> ")
if("exit" == message):
exit()
response = alice.respond(message) # 机器人应答
print(response)
注意:如果出现某某模块找不到的时候,记得使用pip安装对应的模块。
效果图如下所示:
唯一美中不足的是英文,不过没关系,国内有图灵机器人。
代码如下所示:
from urllib.request import urlopen,Request
from urllib.error import URLError
from urllib.parse import urlencode
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
weixin_38508549
- 粉丝: 5
- 资源: 917
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)