Michael Newcomb wrote:
> I would like to create a topic stack and even be able to set multiple
> topics when a pattern is matched. Is there a good AIML way to do this or
> is this an xAIML thing.
The simplest way to write a stack in AIML is this:
<category>
</pattern>PUSHTOPICSTACK</pattern>
<template>
<think>
<set name="topic_index-3><get name="topic_index-2"/></set>
<set name="topic_index-2><get name="topic_index-1"/></set>
<set name="topic_index-1><get name="topic"/></set>
</think>
</template>
</category>
<category>
</pattern>POPTOPICSTACK</pattern>
<template>
<think>
<set name="topic><get name="topic_index-1"/></set>
<set name="topic_index-1><get name="topic_index-2"/></set>
<set name="topic_index-2><get name="topic_index-3"/></set>
</think>
</template>
</category>
The recursive version is a little harder to appreciate, but has the advantage of offering "infinite" depth:
<category>
</pattern>PUSHTOPICSTACK</pattern>
<template>
<think>
<set name="topic_stack><get name="topic"/> <get name="topic_stack"/></set>
</think>
</template>
</category>
<category>
</pattern>POPTOPICSTACK</pattern>
<template>
<srai>POP <get name="topic_stack"/> POP</srai>
</template>
</category>
<category>
</pattern>POP * * POP</pattern>
<template>
<think>
<set name="topic><star index="1"/></set>
<set name="topic_stack><star index="2"/></set>
</think>
</template>
</category>
<category>
</pattern>POP * POP</pattern>
<template>
<think>
<set name="topic><star index="1"/></set>
<set name="topic_stack>undefined</set>
</think>
</template>
</category>
The disadvantage is that you're limited to one-word-topics here, of course. BUTIDONTMINDPERSONALLY.
My favourite way of using multiple topics is to pass through them sequentially:
<topic name=THISTOPIC">
<category>
</pattern>*</pattern>
<template>
<think>
<set name="topic">THATTOPIC</set>
</think>
<sr/>
</template>
</category>
</topic>
<topic name=THATTOPIC">
<category>
</pattern>*</pattern>
<template>
<think>
<set name="topic">ANOTHERTOPIC</set>
</think>
<srai><input/></srai>
</template>
</category>
</topic>
The idea of the above is: after first "filtering" the input through "THISTOPIC", the star gets passed through "THATTOPIC". If there's still no match, try the original input again with "ANOTHERTOPIC", &c. When used with the recursive version of the stack, this style offers limitless possibilities for writing hard-to-grok AIML programs that never terminate on some inputs ;-)
When used with care, it can be quite effective, though.
Dirk
--
_______________________________________________
Search for businesses by name, location, or phone number. -Lycos Yellow Pages
http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10_______________________________________________
programd mailing list
programd@...
http://aitools.org/mailman/listinfo/programd