In playing around with AIML and often trying to get complicated and loop through the words of a sentence and do something like analyze each word I find myself recreating recursive loops again and again for different “commands”. I just figured out I did not have to do that. I made one set of categories that handles the looping and takes a command as a parameter. Others have probably figured this out before but I thought I would share. Please offer comments.
<category>XFOREACHWORD * DO *</pattern>
<template><think><set name=“command”><star index=“2”></set></think><srai>XFOREACHWORD2 <star></srai></template>
</category>
<category>XFOREACHWORD2 * *</pattern>
<template><srai><get name=“command”> <star></srai> <srai>XFOREACHWORD2 <star index=“2”></srai> </template>
</category>
<category>XFOREACHWORD2 *</pattern>
<template><srai><get name=“command”> <star></srai></template>
</category>
<category>XCAPITALIZE <set>preposition</set></pattern>
<template><star></template>
</category>
<category>XCAPITALIZE *</pattern>
<template><formal><star></formal></template>
</category>
<category>XBURST *</pattern>
<template>| <explode><star></explode></template>
</category>