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: IS X BETWEEN Y AND Z
 
 

Leveraging previous posts regarding math and “greater than” and “less than” functionality it is possible to create a BETWEEN category (it is not terribly fast but it is possible).

Using the between category it is possible to bracket ranges.  In the sample pattern below inputs of 1-33 return an “A” rating; 34-66 a “B” rating, and 67-100 a “C” rating.  You do not have to code all 100 inputs in a long condition statement.  It is not fast or efficient and I doubt you could test very many ranges before the system bogs down.  But for simple comparisons this will give your web hosted AIML Pandorabot an edge in the Turing test over other bots!

Code:

<?xml version="1.0" encoding="UTF-8"?>
<aiml versi>
 
<!-- 
This file requires the following other aiml files to work properly -->
<!-- 
File Dependencies: -->
<!-- 
basicmath_greaterthan.aiml -->
<!-- 
basicmath_lessthan.aiml -->

<!-- 
Between: -->
<
category><pattern>IS BETWEEN * AND * </pattern>
<
template><think>
<
set name="ANSWER"></set>
<
set name="ANSWER"><srai>XIF <star/> BETWEEN <star index="2"/> AND <star index="3"/> THEN RETURN TRUE ELSE RETURN FALSE</srai></set>
</
think><condition name="ANSWER">
    <
li value="TRUE">Why yes, <star/> is indeed between <star index="2"/> and <star index="3"/>. </li>
    <
li value="FALSE">Actually no, <star/> is not between <star index="2"/> and <star index="3"/>. </li>
    <
li>Huhwhere am II was thinking about <get name="ANSWER"/></li>
</
condition>
</
template>
</
category>

<
category><pattern>XIF BETWEEN * AND * THEN RETURN * ELSE RETURN *</pattern>
<
template><think>
<
set name="GREATERTHAN"><srai>XMATHCALC <star/> GREATER THAN <star index="2"/></srai></set>
<
set name="LESSTHAN"><srai>XMATHCALC <star/> LESS THAN <star index="3"/></srai></set>
</
think><condition name="GREATERTHAN">
    <
li value="1"><condition name="LESSTHAN">
            <
li value=" dash 1"><star index="4"/></li>
            <
li><star index="5"/></li>
        </
condition>
    </
li>
    <
li><star index="5"/></li>
</
condition>
</
template>
</
category>


<
category><pattern>GIVEN WHAT IS THE RATING</pattern>
<
template><think>
<
set name="ANSWER">NOTFOUND</set>
<
set name="ANSWER"><srai>XIF <star/> BETWEEN 0 AND 34 THEN RETURN ELSE RETURN NOTFOUND</srai></set>
<
condition name="ANSWER" value="NOTFOUND"><set name="ANSWER"><srai>XIF <star/> BETWEEN 33 AND 67 THEN RETURN ELSE RETURN NOTFOUND</srai></set></condition>
<
condition name="ANSWER" value="NOTFOUND"><set name="ANSWER"><srai>XIF <star/> BETWEEN 66 AND 101 THEN RETURN ELSE RETURN NOTFOUND</srai></set></condition>
</
think>The rating is <get name="ANSWER"/></template>
</
category>

</
aiml
 

 
  [ # 1 ]

Sample Output:
Human: is 456 between 123 and 5678
sienna4: Why yes, 456 is indeed between 123 and 5678.

Human: is 11 between 111 and 1111
sienna4: Actually no, 11 is not between 111 and 1111.

Human: given 34 what is the rating
(wait for it…)
sienna4: The rating is B

Human: given 7 what is the rating
(refresh your coffee…)
sienna4: The rating is A

NOTE: samples provided work with positive integers, no negatives, no decimals.  My queues are 30 deep so numbers up to 30 digits long can be compared.

The samples provided require you to ask the question with the smallest number in the range first and the largest last.  Creating a better category/pattern is left as an exercise for the reader.  You will need to test which number is larger and swap them if the user decides to get tricky asking the question.  Such as “is 3 between 4 and 2”.  But now you have a way to test which number is greater!

Now what to work on next?  It seems there is always something to do to add to your chatbot’s knowledge.

 

 
  login or register to react