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: Do you have a store in berln
Bot: Yes, we have recently opened a brand new store in berln! (repeats user's spelling mistake)

In this dialog, both the user and the bot are referring to the city 'Berlin' 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: Do you have a store in berln
Bot: Yes, we have recently opened a brand new store in Berlin! (corrected spelling)

As 'berln' is both missing an 'i' and is lowercased, we have to take the following steps to get it correct in our bot's reply:

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

Normalize the Spelling

We start from the 'User wants to know if we have a store in city' flow which we have created and extended earlier.

  1. Open the 'User wants to know if we have a store in city' in edit mode.
  2. Navigate to the Listener 'Pick up city' in the Flow tab.
  3. Replace _USED_WORDS with the scripting API _.getUsedWords(_.FINAL).join(" ") in the attached script.
  4. Hit 'Save'.

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

Access used words after spelling correction

It consists of three parts:

  1. the method _.getUsedWords() that selects the used words,
  2. the parameter _.FINAL 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 whitespaces 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 is now accomplished, so why not give it a try? Go to tryout and test the following dialog:

User: Do you have a store in berln
Bot: Yes, we have recently opened a brand new store in berlin! (corrected spelling but still lowercased)

Capitalize the city

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

  1. Go back to the Listener 'Pick up city' in the Flow tab.
  2. Add .capitalize() to _.getUsedWords(_.FINAL).join(" ") in the attached script.
  3. Hit 'Save'.

Try it out again!

That's it! You are now all set to try out whether the bot can correct your simple spelling mistakes. Go ahead and have a play in tryout!

Was this page helpful?