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:
- Access the normalized version of the name in the user input.
- 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.
- Open the 'User wants to order a coffee' flow in edit mode.
- Navigate to the Transition 'Get user name' inside the flow.
- 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(" ")}
- Hit 'Save'.
The following picture illustrates the scripting API call in more detail:
It consists of three parts:
- The method _.getUsedWords(), which selects the used words.
- The parameter _.FINAL, which is used to get the final version of _USED_WORDS after passing through all input processing stages.
- The print command .join(" "), which ensures that several words are printed with spaces in between.
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:
- Go back to the Transition 'Get user name' inside the flow.
- 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
- 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!