So I have often heard that you must hard code every combination of a question in AIML making questions like “Is X greater than y?” difficult to answer. It is equally difficult it would seem to answer questions such as “Does Wednesday come after Tuesday?” or “Is object x heavier than object y?”. It would be nice if the chatbot had some basic understanding of “greater than” and “lesser than” operations in its thinking.

An AIML 2.0 Chatbot can be “trained” to understand inequalities just like a human learns by starting out learning the basic inequalities for single digits. Using the same approach as a previous post on addition, all that is needed is to create categories for each combination of the 10 digits comparing one digit to another and returning 1 for greater than, 0 for equals, and -1 for less than. Just as for addition, 100 categories will have to be created. Then the chatbot can examine a number of any size just as a human does by comparing the left most digits one at a time and using the table of 100 single digit comparisons. This approach also allows the thinking of the chatbot to be logged so it can explain how it “reasoned” about its answer, instead of just returning the answer like a simple calculator.

The sample post on addition used stacks because we add digits from right to left. For inequalities we need to use queues (see previous post on queues) because we need to compare digits from left to right. The greater than logic is much easier than addition because there is no “carrying a number” to the next column and because as soon as one digit is greater or less than the other we have our answer.

Sample Output:

Human: is 111 greater than 99

sienna4: Yes, it is greater

Human: how did you decide?

sienna4: Starting with the leftmost digits I asked myself was 1 greater than 0 and decided Yes, it is greater. Therefore the final result was Yes, it is greater.

Human: is 1114 greater than 1113

sienna4: Yes, it is greater

Human: how did you decide

sienna4: Starting with the leftmost digits I asked myself was 1 greater than 1 and decided It is equal, neither greater nor less. Since 1 and 1 are the same I looked at the next 2 digits. I asked myself was 1 greater than 1 and decided It is equal, neither greater nor less. Since 1 and 1 are the same I looked at the next 2 digits. I asked myself was 1 greater than 1 and decided It is equal, neither greater nor less. Since 1 and 1 are the same I looked at the next 2 digits. I asked myself was 4 greater than 3 and decided Yes, it is greater. Therefore the final result was Yes, it is greater.

Human: is 99>99

sienna4: It is equal, neither greater nor less

Human: how did you decide

sienna4: Starting with the leftmost digits I asked myself was 9 greater than 9 and decided It is equal, neither greater nor less. Since 9 and 9 are the same I looked at the next 2 digits. I asked myself was 9 greater than 9 and decided It is equal, neither greater nor less. Since 9 and 9 are the same I looked at the next 2 digits. There were no more digits to compare. Therefore the final result was It is equal, neither greater nor less.

Human: is 88888>99999

sienna4: No, it is less

Obviously the text explanations can be cleaned up and some randomized language choices used but this illustrates the concept.

I will post the sample AIML code in the next post.