我正在尝试借助 AIML 文件构建一个基 native 器人。我可以在其中提出问题,并且将返回该模式的匹配模式。我的 AIML 文件中的示例模式是这样的。
<category>
<pattern>TEST</pattern>
<template>
Hi..This is the testing pattern. How are u doing
</template>
</category>
我正在使用PyAIML用于将 python 与 AIML 集成的包。所以,如果我问“测试”,我得到的答复是 “嗨..这是测试模式。你好吗”。
query --->test
Answer --> Hi..This is the testing pattern. How are u doing
但是如果我将上面的模式更改为
<category>
<pattern>TEST</pattern>
<template>
<html>
<b>Hi..This is the testing pattern. </b> How are u doing
</html>
</template>
</category>
基本上如果我添加 html 标签。然后我的机器人没有响应。它给出了“测试”的空白答案。这里可能有什么问题?这是我的 python 代码
import aiml, sys
class Chat:
def main(self, query):
mybot = aiml.Kernel()
mybot.verbose(False)
mybot.learn('test.aiml')
chatReply = mybot.respond(query)
return chatReply
if __name__ == '__main__':
print Chat().main(sys.argv[1])
此外,如果 html 标签不起作用,因为我在 python 解释器中运行代码,那么如何测试它是否有效。
最佳答案
AIML 文件是从 XML 扩展而来的。您添加的 HTML 实际上被视为 XML 文档的一部分。
要将 HTML 放入 XML 文档中的标记中,您可以使用 XML CDATA
部分,以便您的 HTML 文本被解释为纯文本数据而不是 XML 标记。
<category>
<pattern>TEST</pattern>
<template><![CDATA[
<html>
<b>Hi..This is the testing pattern. </b> How are u doing
</html>]]>
</template>
</category>
这将在输出中包含 HTML 标签。
关于python - 我们可以将 html 标签包含到 AIML 文件的 <template> 中吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30455387/