如何在Python中保存NLTK聊天机器人对话?

时间:2019-12-17 23:33:19

标签: python nltk chatbot

我正在使用在所有chatbot教程中都能看到的通用NLTK.chat代码。它运行完美,但是我想将每个对话都保存到一个文本文件中。我搜索了NLTK.chat.util和NLTK.chat文档,找不到任何一种导出方法。有人知道这样做的方法吗?

这是示例代码:

from nltk.chat.util import Chat, reflections

pairs = [
    ['my name is (.*)', ["hi %1"]],
    ["(hi|hello|hey)", ["hey there", "hello", "sup"]],
    ["(.*) your name", ["My name is S.H.A.N.E."]],
    ["(how are you|how are you feeling)", ["I'm doing well, thank you."]]
]

chat = Chat(pairs, reflections)
chat.converse()

0 个答案:

没有答案