0

我最近使用 python 进行了目标,我尝试了最简单的程序,但即使这样似乎也给我带来了问题,我不知道为什么。

这是python脚本:

import aiml
kernel = aiml.Kernel()
kernel.learn("std-startup.xml")
kernel.respond("load aiml b")

while True:
    print (kernel.respond(raw_input("Enter your message >> ")))

这是 std-startup.xml 的内容:

<category>

    <pattern>
         LOAD AIML B
    </pattern>
    <template>
        <learn>basic-chat.aiml</learn>
    </template>

</category>

这是 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>

我收到此错误警告:找不到输入匹配项:加载目标 b。

我以前见过一些人与他们打交道,我已经尝试过他们的解决方案,但似乎没有任何效果。提前感谢您提供的任何智慧

4

2 回答 2

0

在 python 3 中使用 input 而不是 raw_input 对于 python 2 raw_input 将起作用。

希望有所帮助

于 2018-03-09T07:10:50.750 回答
0

没关系,我让它工作,我取消了以下行:

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

并将其替换为:

kernel.learn("basic-chat.aiml")

这加载了 basic-chat.aiml 文件,我收到了所需的输出,即使这意味着我的 python 文件中有更多的代码行

于 2016-12-11T11:07:07.993 回答