Search code examples
ibm-cloudibm-watsonwatson-assistant

number comparison in IBM Watson Assistant


I am trying to build a BMI calculator inside Watson but it seems like Watson is not supporting number comparison when you use the "Multiple conditioned responses".

<? ($weight /  ($height * $height) ) < 18.5  ?>

This code will throw an error:

SpelParseException when evaluating dialog node ID [response_8_1624288200413]. Condition [<? ($weight / ($height * $height) ) < 18.5 ?>] could not be parsed. Check the syntax of the expression. SpEL syntax error: Expression [<? ($weight / ($height * $height) ) < 18.5 ?>] converted to [<? (context['weight'] / (context['height'] * context['height']) ) < 18.5 ?>] at position 0: EL1070E: Problem parsing left operand

Solution

  • Your example works for me. I can also confirm that IBM Watson Assistant can compare numbers and has other support for math expressions and number processing.

    This is my response text:

    This is: <? ($weight / ($height*$height)) < 18.5 ?>
    

    I set values for weight and height in Manage Context in the "Try it". Depending on the values, it returns either

    This is: true

    or

    This is: false

    Have you set any values during your tests?