Quick Links
AIML Tutorials
MakeAiml Tutorials
C Programming
Download
Advertisements
Template Creation With Macros and Looping Tutorial
Introduction
In this tutorial you will learn how to create complex pattern/template groups using loops in MakeAiml.
MakeAiml Loops
What good would MakeAiml be if it didn't allow a programmer to repeat similar patterns and responses to cut down on work? This is why the concept of looping was introduced.
Looping allows a programmer to take a single response and repeat it for many patterns. Greetings are the most obvious situation where repetition is useful. Since a loop is applied mainly to pattern tags, the loop is considered an extension of the pattern tag by MakeAiml. So, instead of typing p, type pf to instantiate a "Pattern-For loop". The syntax for a Pattern-For loop is pf followed by a list of words to iterate through. Each word is delimited by a space, so for multiple word elements, surround the words in quotes and they will be treated as a single element in the list. To add a placeholder to the list, use a space surrounded by quotes " ". Take a look below:
pf hi hello "what is up" hola howdy "what is going on"
t Hi, it's very nice to meet you!
MakeAiml will look at the above code and see a list of patterns followed by a template to apply to them all. It is shorthand for:
p hi
t Hi, it's very nice to meet you!
p hello
t Hi, it's very nice to meet you!
p what is up
t Hi, it's very nice to meet you!
p hola
t Hi, it's very nice to meet you!
p howdy
t Hi, it's very nice to meet you!
p what is going on
t Hi, it's very nice to meet you!
Loops don't end there though, they can be made much more complex by creating multiple loops for a single template:
p i
pf really " "
pf like love
p being with
pf dogs cats animals
t Really? I enjoy being with animals, too!
What that code will do is create 12 patterns, each with the template: Really? I enjoy being with animals, too!. So, the AIML produced will look like:
<pattern> I REALLY LIKE BEING WITH DOGS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I LIKE BEING WITH DOGS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I REALLY LOVE BEING WITH DOGS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I LOVE BEING WITH DOGS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I REALLY LIKE BEING WITH CATS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I LIKE BEING WITH CATS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I REALLY LOVE BEING WITH CATS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I LOVE BEING WITH CATS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I REALLY LIKE BEING WITH ANIMALS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I LIKE BEING WITH ANIMALS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I REALLY LOVE BEING WITH ANIMALS </pattern>
<template> Really? I enjoy being with animals, too! </template>
<pattern> I LOVE BEING WITH ANIMALS </pattern>
<template> Really? I enjoy being with animals, too! </template>
The next tutorial combines loops and macros to create very complex AIML.
About the Author
Grant Dryden works as a computer engineer. He writes software in C and C++ for embedded systems as well as firmware in VHDL. He has a Bachelor of Science in Computer Engineering.

