AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

AIML Sample: Stacks
 
 

Stacks are useful for LIFO (Last in first out) operations.  There are useful for math operations and I use them in the addition example in the previous post.  Maybe someone is testing your chatbot and asks it to recite the alphabet backwards or type the previous sentence in reverse order or spell a word backwards.

Human: xpushallexploded stack1 abcdefghijklmnopqrstuvwxyz

Human: xpopall stack1
sienna2: z y x w v u t s r q p o n m l k j i h g f e d c b a

Human: xpushall stack1 It is raining today

Human: xpopall stack1
sienna2: today raining is It

Human: xpushallexploded stack1 12345

Human: xpopall stack1
sienna2: 5 4 3 2 1

 

 

 

 
  [ # 1 ]

Here is the code.  Copy the categories for XPUSH STACK 1 * and XPOP STACK1 * to make other stacks.  I use two stacks: STACK1 and STACK2 to perform math calculations in the previous post.

<category>
<
pattern>XPUSHALLEXPLODED * *</pattern>
<
template>
<
srai>XPUSHALL <star/> <explode><star index="2"/></explode></srai>
</
template>
</
category>

<
category>
<
pattern>XPUSHALL * * *</pattern>
<
template>
<
srai>XPUSH <star/> <star index="2"/></srai>
<
srai>XPUSHALL <star/> <star index="3"/></srai>
</
template>
</
category>

<
category>
<
pattern>XPUSHALL * *</pattern>
<
template>
<
srai>XPUSH <star/> <star index="2"/></srai>
</
template>
</
category>

<
category>
<
pattern>XPOPALL *</pattern>
<
template><set name="next"><srai>XPOP <star/></srai></set><condition name="next">
<
li value=""></li>
<
li> <srai>XPOPALL <star/></srai></li>
</
condition>
</
template>
</
category>

<
category>
<
pattern>XPUSH STACK1 *</pattern>
<
template>
<
think>
<
set name="STACK1LEVEL30"><get name="STACK1LEVEL29"/></set>
<
set name="STACK1LEVEL29"><get name="STACK1LEVEL28"/></set>
<
set name="STACK1LEVEL28"><get name="STACK1LEVEL27"/></set>
<
set name="STACK1LEVEL27"><get name="STACK1LEVEL26"/></set>
<
set name="STACK1LEVEL26"><get name="STACK1LEVEL25"/></set>
<
set name="STACK1LEVEL25"><get name="STACK1LEVEL24"/></set>
<
set name="STACK1LEVEL24"><get name="STACK1LEVEL23"/></set>
<
set name="STACK1LEVEL23"><get name="STACK1LEVEL22"/></set>
<
set name="STACK1LEVEL22"><get name="STACK1LEVEL21"/></set>
<
set name="STACK1LEVEL21"><get name="STACK1LEVEL20"/></set>
<
set name="STACK1LEVEL20"><get name="STACK1LEVEL19"/></set>
<
set name="STACK1LEVEL19"><get name="STACK1LEVEL18"/></set>
<
set name="STACK1LEVEL18"><get name="STACK1LEVEL17"/></set>
<
set name="STACK1LEVEL17"><get name="STACK1LEVEL16"/></set>
<
set name="STACK1LEVEL16"><get name="STACK1LEVEL15"/></set>
<
set name="STACK1LEVEL15"><get name="STACK1LEVEL14"/></set>
<
set name="STACK1LEVEL14"><get name="STACK1LEVEL13"/></set>
<
set name="STACK1LEVEL13"><get name="STACK1LEVEL12"/></set>
<
set name="STACK1LEVEL12"><get name="STACK1LEVEL11"/></set>
<
set name="STACK1LEVEL11"><get name="STACK1LEVEL10"/></set>
<
set name="STACK1LEVEL10"><get name="STACK1LEVEL9"/></set>
<
set name="STACK1LEVEL9"><get name="STACK1LEVEL8"/></set>
<
set name="STACK1LEVEL8"><get name="STACK1LEVEL7"/></set>
<
set name="STACK1LEVEL7"><get name="STACK1LEVEL6"/></set>
<
set name="STACK1LEVEL6"><get name="STACK1LEVEL5"/></set>
<
set name="STACK1LEVEL5"><get name="STACK1LEVEL4"/></set>
<
set name="STACK1LEVEL4"><get name="STACK1LEVEL3"/></set>
<
set name="STACK1LEVEL3"><get name="STACK1LEVEL2"/></set>
<
set name="STACK1LEVEL2"><get name="STACK1LEVEL1"/></set>
<
set name="STACK1LEVEL1"><star/></set>
</
think>
</
template>
</
category>

<
category>
<
pattern>XPOP STACK1</pattern>
<
template><get name="STACK1LEVEL1"/><think>
<
set name="STACK1LEVEL1"><get name="STACK1LEVEL2"/></set>
<
set name="STACK1LEVEL2"><get name="STACK1LEVEL3"/></set>
<
set name="STACK1LEVEL3"><get name="STACK1LEVEL4"/></set>
<
set name="STACK1LEVEL4"><get name="STACK1LEVEL5"/></set>
<
set name="STACK1LEVEL5"><get name="STACK1LEVEL6"/></set>
<
set name="STACK1LEVEL6"><get name="STACK1LEVEL7"/></set>
<
set name="STACK1LEVEL7"><get name="STACK1LEVEL8"/></set>
<
set name="STACK1LEVEL8"><get name="STACK1LEVEL9"/></set>
<
set name="STACK1LEVEL9"><get name="STACK1LEVEL10"/></set>
<
set name="STACK1LEVEL10"><get name="STACK1LEVEL11"/></set>
<
set name="STACK1LEVEL11"><get name="STACK1LEVEL12"/></set>
<
set name="STACK1LEVEL12"><get name="STACK1LEVEL13"/></set>
<
set name="STACK1LEVEL13"><get name="STACK1LEVEL14"/></set>
<
set name="STACK1LEVEL14"><get name="STACK1LEVEL15"/></set>
<
set name="STACK1LEVEL15"><get name="STACK1LEVEL16"/></set>
<
set name="STACK1LEVEL16"><get name="STACK1LEVEL17"/></set>
<
set name="STACK1LEVEL17"><get name="STACK1LEVEL18"/></set>
<
set name="STACK1LEVEL18"><get name="STACK1LEVEL19"/></set>
<
set name="STACK1LEVEL19"><get name="STACK1LEVEL20"/></set>
<
set name="STACK1LEVEL20"><get name="STACK1LEVEL21"/></set>
<
set name="STACK1LEVEL21"><get name="STACK1LEVEL22"/></set>
<
set name="STACK1LEVEL22"><get name="STACK1LEVEL23"/></set>
<
set name="STACK1LEVEL23"><get name="STACK1LEVEL24"/></set>
<
set name="STACK1LEVEL24"><get name="STACK1LEVEL25"/></set>
<
set name="STACK1LEVEL25"><get name="STACK1LEVEL26"/></set>
<
set name="STACK1LEVEL26"><get name="STACK1LEVEL27"/></set>
<
set name="STACK1LEVEL27"><get name="STACK1LEVEL28"/></set>
<
set name="STACK1LEVEL28"><get name="STACK1LEVEL29"/></set>
<
set name="STACK1LEVEL29"><get name="STACK1LEVEL30"/></set>
<
set name="STACK1LEVEL30"></set>
</
think></template>
</
category
 

 
  login or register to react