[英]Can we include html tags into <template> of AIML files
我正在嘗試借助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解釋器中運行代碼而無法使用,那么如何測試它是否可以正常工作。
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標記。
我為此使用了替代方法。 根據此Wiki頁面,AIML可以包含html標簽。 但是用pyaiml卻沒有成功。 所以我將AIML模式更改為
<category>
<pattern>TEST</pattern>
<template>
((html))
((b))Hi..This is the testing pattern. ((/b)) How are u doing
((/html))
</template>
</category>
因此,在響應中,我將用'<'替換'(('。我知道它不是一個合適的解決方案,但是是一個替代方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.