Hi Everyone,
I was inspired by Steve Worswick’s presentation at Chatbots 3.2 to try my hand at a simple AIML database. The files are too large to post in their entirety, so I attached them. Here are the essential ideas.
Material type attributes are set in one file:
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0">
<topic name="BOOK ATTRIBUTES">
<category>
<pattern>BKS</pattern>
<template>
<think>
<set name="itype_cap">Books</set>
<set name="itype">books</set>
<set name="co limit">any many as you wish. There is no limit.</set>
<set name="lper">two weeks</set>
<set name="fine">$0.10 per day</set>
<set name="rlimit">four</set>
<set name="material type attr">BOOK ATTRIBUTES</set>
<set name="topic"></set>
</think>
<srai>MTSORT</srai>
</template>
</category>
</topic>
<topic name="CD ATTRIBUTES">
<category>
<pattern>CDS</pattern>
<template>
<think>
<set name="itype_cap">CDs</set>
<set name="itype">CDs</set>
<set name="co limit">20</set>
<set name="lper">two weeks</set>
<set name="fine">$0.10 per day</set>
<set name="rlimit">four</set>
<set name="material type attr">CD ATTRIBUTES</set>
<set name="topic"></set>
</think>
<srai>MTSORT</srai>
</template>
</category>
</topic>
</aiml>
etc.etc…..
Then the attributes are invoked using a second file:
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0">
<category>
<pattern>HOW LONG *</pattern>
<template>
<think>
<set name="answr"><star/></set>
<set name="attr1">lper</set>
<set name="attr2">HOW LONG</set>
<set name="topic">ATTRSORT</set>
</think>
<srai>ATTRSORT</srai>
</template>
</category>
<topic name="ATTRSORT">
<category>
<pattern>ATTRSORT</pattern>
<template>
<think>
<get name="answr"/>
<set name="message">no match</set>
<condition name="answr">
<li value="BOOK"><set name="message">book</set></li>
<li value="* BOOK"><set name="message">book</set></li>
<li value="BOOK *"><set name="message">book</set></li>
<li value="* BOOK *"><set name="message">book</set></li>
<li value="BOOKS"><set name="message">book</set></li>
<li value="* BOOKS"><set name="message">book</set></li>
<li value="BOOKS *"><set name="message">book</set></li>
<li value="* BOOKS *"><set name="message">book</set></li>
<li value="CD"><set name="message">cd</set></li>
<li value="* CD"><set name="message">cd</set></li>
<li value="CD *"><set name="message">cd</set></li>
<li value="* CD *"><set name="message">cd</set></li>
<li value="CDS"><set name="message">cd</set></li>
<li value="* CDS"><set name="message">cd</set></li>
<li value="CDS *"><set name="message">cd</set></li>
<li value="* CDS *"><set name="message">cd</set></li>
</condition>
</think>
<condition name="message">
<li value="book"><think><set name="topic">BOOK ATTRIBUTES</set></think><srai>BKS</srai></li>
<li value="cd"><think><set name="topic">CD ATTRIBUTES</set></think><srai>CDS</srai></li>
</condition>
</template>
</category>
</topic>
<category>
<pattern>MTSORT</pattern>
<template>
<think>
<get name="attr1"/>
<condition name="attr1">
<li value="QUANT"><set name="message">co limit</set></li>
<li value="LPER"><set name="message">lper</set></li>
<li value="FINE"><set name="message">fine</set></li>
<li value="RLIMIT"><set name="message">rlimit</set></li>
</condition>
</think>
<condition name="message">
<li value="stop"><set name="topic"></set>O.K. Ill stop.</li>
<li value="co limit"><srai>ITEMQUANT</srai></li>
<li value="lper"><srai>ITEMLPER</srai></li>
<li value="fine"><srai>ITEMFINE</srai></li>
<li value="rlimit"><srai>ITEMRLIMIT</srai></li>
</condition>
</template>
</category>
<category>
<pattern>ITEMQUANT</pattern>
<template>
<random>
<li>You may check out <get name="co limit"/> <get name="itype"/>. </li>
<li>You can take out <get name="co limit"/> <get name="itype"/>. </li>
</random>
<think>
<set name="topic"></set>
</think>
</template>
</category>
<category>
<pattern>ITEMLPER</pattern>
<template>
<random>
<li><get name="itype_cap"/> circulate for <get name="lper"/>. </li>
<li>You may keep <get name="itype"/> for <get name="lper"/>. You may renew them up to <get name="rlimit"/> times as long as no one else
has placed a hold on them. </li>
<li>You may keep your <get name="itype"/> for <get name="lper"/>.</li>
</random>
<think>
<set name="topic"></set>
</think>
</template>
</category>
<category>
<pattern>ITEMFINE</pattern>
<template>
<random>
<li><get name="itype_cap"/> accrue fines at a rate of <get name="fine"/>. </li>
<li><get name="itype_cap"/> that are overdue accrue fines at a rate of <get name="fine"/>.</li>
<li>Late fees are <get name="fine"/> for overdue <get name="itype"/>.</li>
</random>
<think>
<set name="topic"></set>
</think>
</template>
</category>
<category>
<pattern>ITEMRLIMIT</pattern>
<template>
<random>
<li><get name="itype_cap"/> may be renewed <get name="rlimit"/> times. <get name="itype_cap"/> may not be renewed
if another patron has placed a hold on them. </li>
<li>You can renew <get name="itype"/> up to <get name="rlimit"/> times as long as no one else has placed a hold on them.</li>
<li>As long as no one else has placed a hold on your <get name="itype"/>, you may renew them up to <get name="rlimit"/> times.</li>
</random>
<think>
<set name="topic"></set>
</think>
</template>
</category>
</aiml>
etc.etc….
This works fairly well. My questions are:
1. Is there a simpler or more elegant way to code this? Don’t be angry for my asking, but is this sort of thing easier in chatscript?
2. Is there a way to invoke more than one topic, i.e. “topic,” “topic2,” etc.? I’d like the bot to “remember” both material types and attribute - loan period, fine, checkout and renewal limits, so if a user asks, “How many books can I take out?” then asks “What are their fines?” then “What about CDs?” the bot will know that the topic was “fines.”
Thanks!
OK - the uploads aren’t working. I’ll try again.

RSS AI Zone




