我们可以将html标签包含在AIML文件的<template>中吗?

时间:2015-05-26 10:02:00

标签: python html artificial-intelligence aiml

我正在尝试在AIML文件的帮助下构建一个基本机器人。在哪里我可以提出一个问题,并且将为该模式返回匹配的模式。样本模式在我的AIML文件中。

<category>
    <pattern>TEST</pattern>
    <template>
        Hi..This is the testing pattern. How are u doing
    </template>
</category>

我正在使用PyAIML包来将python与AIML集成。所以,如果我问&#34;测试&#34;,我会得到响应 &#34;嗨......这是测试模式。你好吗&#34;。

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标签。然后我的机器人没有回应。它为&#34; test&#34;提供了空白答案。这可能是什么问题?这是我在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解释器中运行代码,那么如何测试它是否可行。

2 个答案:

答案 0 :(得分:2)

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标记。

答案 1 :(得分:1)

我使用了替代品。根据此wiki页面,AIML可以包含h​​tml标记。但是使用pyaiml,它没有成功。所以我改变了我的AIML模式

<category>
    <pattern>TEST</pattern>
    <template>
        ((html))
        ((b))Hi..This is the testing pattern. ((/b)) How are u doing
        ((/html))
    </template>
</category>

所以在回复中我将替换'(('with'&lt;'。我知道它不是一个合适的解决方案,但它是另一种选择。

相关问题