简体   繁体   中英

Can we include html tags into <template> of AIML files

I am trying to build a basic bot with the help of AIML file. Where I can ask a question and matched pattern will be returned for that pattern. Sample pattern is this in my AIML file.

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

I am using PyAIML package for integrating python with AIML. So, if I ask "test", I get the response as "Hi..This is the testing pattern. How are u doing".

query --->test
Answer --> Hi..This is the testing pattern. How are u doing

But if I change my above pattern to

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

Basically If I add html tags. Then my bot does not respond. It gives blank answer for "test". What can be the problem here? Here is my code in 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])

Also if html tags are not working because I am running the code in python interpreter, then how to test if it will work or not.

AIML files are extended from XML. The HTML you have added is actually being seen as part of the XML document.

To put HTML into a tag within an XML document, you could use XML CDATA section so that your HTML text is interpreted as purely textual data rather than XML tags.

<category>
    <pattern>TEST</pattern>
    <template><![CDATA[
        <html>
        <b>Hi..This is the testing pattern. </b> How are u doing
        </html>]]>
    </template>
</category>

This will then contain the HTML tags in the output.

I used a alternative for this. According to this wiki page, AIML can contain html tags. But with pyaiml, it didn't worked out. So I changed my AIML patterns as

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

So in the response I will be replacing '((' with '<'. I know its not a proper solution, but its a alternative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM