AIML Use Cases: Part 1

If you’re not watching repositories on Pandorabots on Github yet, now is the time to start —

A number of free SDKs for the Pandorabots API are available in many popular languages including:

Plus you can download Rosie, an AIML framework that can be used as a base for your chatbot and save you the hassle of writing reductions to capture common conversational interactions.

Rosie also includes some handy AIML utility files. These contain tools and functions to improve your bot’s conversational abilities, debug your bot, and track user information retained in your bot. For example, the roman.aiml file, along with set file, digit allows you to convert numbers into roman numerals.

AIML is more than just for natural language processing. AIML can be crafted for a variety of purposes including debugging during bot development, or application-to-bot interaction (hidden from your end-user).

In this post, we’ll explore a few simple examples of what you can do. We encourage you to take these and adapt them for use in your own projects.

XSAY *

This pattern returns a normalized version of an input (check out our Tutorial for details about normalization). You might want to use this debugging your bot as a quick way to see how inputs are normalized before being processed by the AIML interpreter.

<category> 
<pattern>XSAY *</pattern>
<template><star/></template>
</category>

Input: Xsay google.com 
 Output: google dot com

Remember, there is nothing magical about this pattern. With any of these examples, you can customize the pattern with your own keyword, e.g. ECHO * or NORMALIZED * or BLAHBLAHBLAH *

HANDLING PREDICATES

You might want your application to handle predicates to customize your app. You can use this pattern example to return the value of a predicate:

<category> 
<pattern>XGET *</pattern>
<template><get><name><star/></name></get></template>
</category>

Input: XGET haircolor 
 Output: unknown

Your application might need to set a predicate explicitly (without using the conversational AIML). This pattern example sets a predicate whose name is a single word but whose value can be one or more words:

<category>  
<pattern>XSET * *</pattern>
<template>
<think><set><name><star index="1"/></name><star index="2"/></set></think>
<star index="1"/> has been set to <star index="2"/>
</template>
</category>

Input: xset haircolor dark brown 
 Output: haircolor has been set to dark brown

If you want to set multiple predicates in one input, see how the example below uses a keyword delimiter between predicates. This example can be extended to support more than 2 predicates and their values.

NOTE: the Pandorabots platform limits the total number of characters received in a single input so be careful using this example!

<category>  
<pattern>XSET * * XNEXT * *</pattern>
<template>
<think>
<set><name><star index="1"/></name><star index="2"/></set>
<set><name><star index="3"/></name><star index="4"/></set>
</think>
Predicates restored: <star index="1"/>, <star index="3"/>
</template>
</category>

Input: xset haircolor strawberry blond XNEXT eyecolor hazel 
 Output: Predicates restored: haircolor, eyecolor

Including both XSET category examples in your AIML will allow your application to set one or two predicates with one input as needed.

Again, these patterns can be customized with your own keywords — nothing magical about XGET, XSET or XNEXT. And for setting predicates, you don’t even have to return a response if you don’t need it.

Happy AIML coding!


Originally published at blog.pandorabots.com on February 11, 2015.

Show your support

Clapping shows how much you appreciated Pandorabots’s story.