AI Zone Admin Forum Add your forum
Questions about AIML databases
 
 

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 wishThere 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.KI'll 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.

 

 

 
  [ # 1 ]

{edit}

See the links below for the files mentioned in the previous post. Be sure to right-click the links and select “Save Link as…” (or similar), rather than directly opening the links:

http://www.geekcavecreations.com/Downloads/cbo/newyear/attribute_sort.aiml

http://www.geekcavecreations.com/Downloads/cbo/newyear/material_type_attributes.aiml

{/edit}

 

 
  [ # 2 ]

You should set up the database like this. No need for topics. The top category is a catchall in case someone asks about borrowing something the library doesn’t stock.

<category>
<
pattern>ITEMCHECK *</pattern>
<
template>
<
think>
<
set name="co limit">UNKNOWN</set>
<
set name="lper">UNKNOWN</set>
<
set name="fine">UNKNOWN</set>
<
set name="rlimit">UNKNOWN</set>
</
think>
</
template>
</
category>

<
category>
<
pattern>ITEMCHECK BOOKS</pattern>
<
template>
<
think>
<
set name="co limit">any many as you wishThere is no limit.</set>
<
set name="lper">two weeks</set>
<
set name="fine">$0.10 per day</set>
<
set name="rlimit">four</set>
</
think>
</
template>
</
category>

<
category>
<
pattern>ITEMCHECK CDS</pattern>
<
template>
<
think>
<
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>
</
think>
</
template>
</
category

You can then query the data by using categories such as:

<category>
<
pattern>HOW MANY CAN I TAKE OUT</pattern>
<
template>
<
srai>ITEMCHECK <star/></srai>
<
condition name="co limit">
<
li value="UNKNOWN">Sorry but you can't borrow <star/> here. We are a library remember.</li>
<li>You can borrow up to <get name="co limit"/> <star/>.</li>
</condition>
</template>
</category>

<category>
<pattern>WHAT IS THE FINE FOR LATE *</pattern>
<template>
<srai>ITEMCHECK <star/></srai>
<condition name="fine">
<li value="UNKNOWN">Sorry but you can'
t borrow <star/> hereWe are a library remember.</li>
<
li>The fine is <get name="fine"/> for any late <star/>.</li>
</
condition>
</
template>
</
category

This will lead to conversations such as:

Human: how many cds can I take out
Bot: You can borrow up to 20 cds.
 
Human: what is the fine for late books
Bot: The fine is $0.10 per day for any late books.

Human: How many bowls of sugar can I take out
Bot: Sorry but you can’t borrow bowls of sugar here. We are a library remember.

To address point 2 WILL need the use of topics. When the user mentions a fine, set a topic to “FINES” and then if the bot is asked, “what about CDs”, the bot will know it is dealing with fines.

Hope that helps.

 

 
  login or register to react
‹‹ Funny A.I. iPhone App Review      CallMom ››