无法通过 Python 在 AIML 中加载模式
Unable to load patterns in AIML via Python
我已经通过 pip 安装了 AIML 并编写了文件 startup.py, std-startup.xml, basic.aiml 和 bot_brain.brn 在 core 文件夹中。当我尝试 运行 startup.py 时,我收到此警告:
Loading std-startup.xml... done (0.06 seconds)
WARNING: No match found for input: load aiml b
Kernel bootstrap completed in 0.10 seconds
Saving brain to core/bot_brain.brn... done (0.00 seconds)
这是std-startup.xml的内容:
<aiml version="1.0.1" encoding="UTF-8">
<!-- std-startup.xml -->
<category>
<pattern>load aiml b</pattern>
<template>
<learn>basic.aiml</learn>
</template>
</category>
</aiml>
这是Python脚本:
import aiml
import os
kernel = aiml.Kernel()
if os.path.isfile("core/bot_brain.brn"):
kernel.bootstrap(brainFile = "core/bot_brain.brn")
else:
kernel.bootstrap(learnFiles = "std-startup.xml", commands = "load aiml b")
kernel.saveBrain("core/bot_brain.brn")
while True:
msg = raw_input(">")
if msg == "exit":
exit(0)
elif msg == "save":
kernel.saveBrain("core/bot_brain.brn")
else:
bot_response = kernel.respond(msg)
print("bot: " + bot_response)
对于每个输入,我都会收到错误 No match found for input
。我做错了什么?一切都在同一个目录中,除了 bot_brain.brn.
问题已解决;我必须用大写字母输入它:
<category>
<pattern>LOAD AIML B</pattern>
<template>
<learn>basic.aiml</learn>
</template>
</category>
我已经通过 pip 安装了 AIML 并编写了文件 startup.py, std-startup.xml, basic.aiml 和 bot_brain.brn 在 core 文件夹中。当我尝试 运行 startup.py 时,我收到此警告:
Loading std-startup.xml... done (0.06 seconds)
WARNING: No match found for input: load aiml b
Kernel bootstrap completed in 0.10 seconds
Saving brain to core/bot_brain.brn... done (0.00 seconds)
这是std-startup.xml的内容:
<aiml version="1.0.1" encoding="UTF-8">
<!-- std-startup.xml -->
<category>
<pattern>load aiml b</pattern>
<template>
<learn>basic.aiml</learn>
</template>
</category>
</aiml>
这是Python脚本:
import aiml
import os
kernel = aiml.Kernel()
if os.path.isfile("core/bot_brain.brn"):
kernel.bootstrap(brainFile = "core/bot_brain.brn")
else:
kernel.bootstrap(learnFiles = "std-startup.xml", commands = "load aiml b")
kernel.saveBrain("core/bot_brain.brn")
while True:
msg = raw_input(">")
if msg == "exit":
exit(0)
elif msg == "save":
kernel.saveBrain("core/bot_brain.brn")
else:
bot_response = kernel.respond(msg)
print("bot: " + bot_response)
对于每个输入,我都会收到错误 No match found for input
。我做错了什么?一切都在同一个目录中,除了 bot_brain.brn.
问题已解决;我必须用大写字母输入它:
<category>
<pattern>LOAD AIML B</pattern>
<template>
<learn>basic.aiml</learn>
</template>
</category>