【问题标题】:Can we include html tags into <template> of AIML files我们可以在 AIML 文件的 <template> 中包含 html 标签吗
【发布时间】:2015-05-26 10:02:00
【问题描述】:

我正在尝试借助 AIML 文件构建一个基本的机器人。我可以在哪里提出问题,并且将为该模式返回匹配的模式。示例模式在我的 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解释器中运行代码而不起作用,那么如何测试它是否会起作用。

【问题讨论】:

    标签: python html artificial-intelligence aiml


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我为此使用了替代方法。根据这个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>
      

      所以在回复中,我将用 '

      【讨论】:

        猜你喜欢
        • 2015-12-26
        • 2013-06-14
        • 1970-01-01
        • 2014-08-01
        • 1970-01-01
        • 2021-08-23
        • 2016-06-24
        • 2011-01-10
        • 1970-01-01
        相关资源
        最近更新 更多