AI Zone Admin Forum Add your forum

NEWS: survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Substitutions of arrays in triggers

If I create an array like this:
! array numbers = 1 2 3 4 5 6 7 8 9 0

Is it possible then to add substitutions about these triggers? Example:
! number 1 = one
! number 2 = two
! number 3 = three
! number 4 = four
! number 5 = five
! number 6 = six
! number 7 = seven
! number 8 = eight
! number 9 = nine
! number 0 = zero


  [ # 1 ]

Arrays are designed to reduce repetition when writing triggers that use common sets of words, for example:

what color is my (red|blue|green|yellow) *
my favorite color is (red|blue|green|yellow)
what color was * (red|blue|green|yellow) * 

Instead of needing to copy/paste that whole list of colors all over the place, you put it into an array and just use that in the triggers instead,

! array colors red blue green yellow
what color is my (@colors) *
my favorite color is (@colors)
what color was * (@colors) * 

As such, the text of the array items is the same text that you would otherwise have written directly into a trigger.

How substitutions work: when a user message is input into the bot, it preprocesses the message and runs it through the substitutions to “normalize” it, so that if the user says “what’s up?” it comes out as “what is up” and you only have to write one trigger to answer that. Or it can turn slang and shortcuts into their more proper forms, “gf” becomes “girlfriend”, “brb” becomes “be right back” and so on, so that you don’t have to deal with all these “aliases” in your triggers.

So you could do something like this:

// array of numbers
! array numbers 0 1 2 3 4 5 6 7 8 9

// if the user spells out a word, like "eight", translate it
// to its decimal version
sub one 1
sub two 2
sub three 3
// etc...

what is (@numbers) + (@numbers)
- <
star1> + <star2> = <call>add <star1> <star2></call>

// but since the word "eight" becomes 8, you can't use it in a
// trigger directly like this:
give me pieces of eight
Where are we againMonkey Island?

// it would have to be...
give me pieces of 8 

Or you could flip the whole thing around, make your array be of the word forms (“one”, “two”, ...) and translate numbers into words.

I would advise against all of this though, because if you’re translating numbers to words in any direction, that’s opening Pandora’s Box because there’s an infinite number of numbers. If the user says “234” should it be translated into “two hundred and thirty four”, and would you want to write that many !sub lines? wink

RiveScript triggers have a special kind of wildcard that only matches numeric values. Here’s an example where the user could tell the bot their age:

// "i am twenty years old"
i am _ years old
Tell me that again but use a number this time.

// "i am 20 years old
i am # years old
- <set age=<star>>I'll remember you're <get ageyears old.

// the * wildcard matches anything, so if you don't care whether it's a word
// or a number then you can use that
i am years old
- <set age=<star>>I'll remember that you're <get ageyears old,\s
but I'd be hesitant to do any numerical arithmetic on that. 

(All three of those triggers could coexist in the same bot brain, and they would be sorted by triggers containing _ wildcards first, then # wildcards second, and finally the “wildcard wildcard” * last).

_ = only matches words but not numbers
# = only matches numbers but not words
* = matches everything


  [ # 2 ]

1) Wow! I am very happy to can write lists of triggers!
2) You are right, substitute numbers from decimal version to words and from words to decimal is very dangerous! I will not do it , thanks.



  login or register to react
‹‹ Multiple triggers      chatDIR is not defined ››