1
votes

Assume that I have a context variable with an array, e.g., the recognized entities. In the Watson Conversation Service (WCS) it is possible to either return responses in sequence or in random. What I am looking for is to have a single response in the dialog node, but to randomly pick an array entry and return it. I know that I can use Spring Expression Language (SpEL) for advanced evaluations. This is not working and gives an error:

Here is a random entity:
 <? entities[(int) (entities.size() * T(java.lang.Math).random() ].value ?>

What can be done to produce a valid integer value for array access?

1

1 Answers

0
votes

I found a way around the error. The random value needs to be transformed into / casted to an integer. The following response in a Watson Conversation dialog node returns a random entry of the recognized entities.

Here is a random entity:
 <? entities[(entities.size() * T(java.lang.Math).random()).intValue()].value ?>

When passing in some options from the app to WCS, the dialog can now randomly choose one and return it as response.