python3 8使用aiml總結

2021-10-09 10:34:20 字數 2043 閱讀 4472

# 切換到.aiml所在工作目錄

os.chdir(alice_path)

alice = aiml.kernel()

# 通過std-startup.xml啟動aiml

alice.learn("std-startup.xml")

# aiml檔案有修改時可以通過load aiml b(在xml中pattern配置)進行修改

alice.respond('load aiml b')

while true:

# 對話接入位置

print(alice.respond(input("enter your message >> ")))

std-startup.xml--固定寫法,可配置多個aiml
load aiml b

basic_chat.aiml

stude.aiml

hello

well, hello!

你是男生嗎?

先告訴我你是麼?

是先告訴我你是麼?

我也是

不是先告訴我你是麼?

我也不是

張的性別是

李的性別是

你知道*的性別是*

的性別是

你好你好1你好2

你好3你好4

你好5你好6

我是*你好

我的姓名是*

你的姓名是

think我是*

你好

我的姓名是*

你的姓名是

我*我也開心

我也不開心

what are you

i'm a bot, silly!

* 答案是 *

python3 learn.py '' ''

basic_chat.aiml

好的我學會了

# -*- coding: utf-8 -*-

import sys

# print(sys.ar**)

template = """

{}{}

"""file = open("basic_chat.aiml","rb+")

content = file.read()

# seek定位至aiml中最後一行之前,刪除

file.seek(-7,1)

file.truncate()

file.close()

file1 = open("basic_chat.aiml","a")

file1.write(template.format(sys.ar**[1],sys.ar**[2])+"\n"+"")

file1.close()

Python3 8下使用tornado報錯

tornado官網文件 在windows上,tornado需要使用windowsselectoreventloop。這是python 3.7和更早版本的預設值,但python 3.8預設為事件迴圈,與tornado不相容。在python 3.8中使用tornado的應用程式必須在其主檔案 函式的開頭...

python3 8動態人臉識別

pip install dlib pip python opencv coding utf 8 從視屏中識別人臉,並實時標出面部特徵點 import dlib 人臉識別的庫dlib import cv2 影象處理的庫opencv 使用特徵提取器get frontal face detector de...

python3 8降到3 6安裝dlib

安裝anaconda 輸入命令conda info envs可以檢視python3.5是否配置完成 可以看到python35存在,說明python3.5配置成功 啟用python35 activate python35 可以看到確實啟用了可以進入3.5版本進行 編輯了 4 基於python3.6安裝...