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 <calculate> tag
 
 

After experimenting with the UBERBOT I want to suggest a new maths tag:

<calculate>  value1 operator value2 </calculate>

Value1 and Value2 are integers to a minimum of 6 digits and operator can be one of: + - /  *. The AIML interpreter calculates the expression and returns it as the value of <calculate>. Calculations are restricted to the format number operator number to make it easy to implement the <calculate> tag, and to make it easy to guard against SQL injection, or other types of injection for non SQL based interpreters. The limitation in the form value1 operator value2 is not serious as <calculate> can be nested if needed. If the calculation is successful it returns a number commencing with a digit 0..9, otherwise it returns an error message such as “number is too large”, “inputs are not a number” etc.

Other changes

The new tag returns a number (starting with 0..9) or an error message which starts with a letter. To help report errors we must change the <li value=”...”> tag when used in a condition. Currently “...” can be * to catch any value, however we need to separate numbers from error messages. Thus value=”...” should be extended to allow basic expressions such as [0-9] to match a single digit.

Example

<category>
  < pattern > CALCULATE * FOR ME < /pattern >
  <template>
  <think>
    <set var=“result”><calculate><star/ ></calculate></set>
  </think>
  <condition>
    <li var=“result” value=”[0-9]*”> The answer is <get var=“result”/ > </li>
    <li> It is too complicated </li>
  </condition>
  </template>
</category>

The category interprets the input using <calculate>. If the answer is a valid number it is returned, otherwise an error message is returned. For example “CALCULATE 30 + 12 FOR ME” returns “The answer is 42” whereas “CALCULATE MY STAR SIGN FOR ME” returns “It is too complicated”.

Rationale

This tag is required as core AIML is currently unable to do basic maths. Although a work around is possible by coding maths routines in AIML, this is an ineffective and time consuming approach. The processor on all modern computers can add and multiply numbers in nanoseconds, whereas interpreted solutions take much longer. Thus basic maths tasks should be offloaded to the AIML interpreter instead of being coded via maths categories.

 

 
  login or register to react