Teneo Developers

Share to

Normalize the user's spelling

We have already seen how you can use the user's own words in your bot's reply. Here we will show you how to normalize the user's words before returning them. This can be useful for slightly misspelled inputs like the following:

User: I want to order an espresso
Bot: Ok, what name shall I note for the order?

User: Elizabth
Bot: Thanks for your order, elizabth. Your espresso will be ready for pickup in 5 minutes. (misspelled and lowercased name)

In this dialogue, both the user and the bot are referring to the name 'Elizabeth', which the user has misspelled. The dialog nevertheless succeeded because Teneo has a built-in spelling normalization. We can access the normalized spelling of the user input to get the following dialog instead:

User: I want to order an espresso
Bot: Ok, what name shall I note for the order?

User: elizabth
Bot: Thanks for your order, Elizabeth. Your espresso will be ready for pickup in 5 minutes. (corrected spelling)

As 'Elizabth' is misspelled, we have to take the following steps to use the correctly spelled word in our bot's reply:

  1. Access the normalized version of the name in the user input.
  2. Make the name uppercase in the output.

Normalize the Spelling

We start from the 'User wants to order a coffee' flow which we have created and extended earlier.

  1. Open the 'User wants to order a coffee' flow in edit mode.
  2. Navigate to the Transition 'Get user name' inside the flow.
  3. Replace the _USED_WORDS with the scripting API .getUsedWords(.FINAL).join(" ") in the attached script by pasting in the following condition: %$PERSON.NER^{userNameForOrder = _.getUsedWords(_.FINAL).join(" ")}
  4. Hit 'Save'.

The following picture illustrates the scripting API call in more detail:

Build - Normalize the user's spelling: used words final2

It consists of three parts:

  1. The method _.getUsedWords(), which selects the used words.
  2. The parameter _.FINAL, which is used to get the final version of _USED_WORDS after passing through all input processing stages.
  3. The print command .join(" "), which ensures that several words are printed with spaces in between.

A full list of possible parameters to be passed to this scripting API method is given here.

Try it out!

The spelling normalization part has now been implemented, so let's give it a try! Go to Tryout and test the following dialog:

User: I want to order an espresso
Bot: Ok, what name shall I note for the order?

User: Elizabth
Bot: Thanks for your order, elizabeth. Your espresso will be ready for pickup in 5 minutes. (corrected spelling but still lowercase)

Capitalize the name

Now that the spelling is fixed, it would be ideal to return the name with the first letter capitalized. To do this, simply:

  1. Go back to the Transition 'Get user name' inside the flow.
  2. Replace the condition by adding .capitalize() to _.getUsedWords(_.FINAL).join(" ") in the attached script by pasting in the following condition:

tlml

1%$PERSON.NER^{userNameForOrder = _.getUsedWords(_.FINAL).join(" ").capitalize()}
2
  1. Hit 'Save'.

For cases where you do not want to normalize the name but still capitalize the first letter use this condition instead:

tlml

1%$PERSON.NER^{userNameForOrder = _.getUsedWords(_.FINAL).join(" ").capitalize()} / (! %$PERSON.NER & (*)^{userNameForOrder = _.getUsedWords(_.FINAL).join(" ").capitalize()} )
2

Try it out again!

That's it! You are now all set to test whether the bot can correct your simple spelling mistakes. Go ahead and experiment in Tryout!