Advanced Usage

Teneo's DateTime Handler comes with a wide range of pre-defined date and time expressions together with their interpretations. However, if you want to modify the existing date time expressions or add new date or time expressions to be recognized by your bot, you can add them directly to your solution with no advanced scripting skills required. On this page we will show you how to:

  1. Modify existing date and time expressions.
  2. Add new date and time expressions to the DateTimeHandler.

Modify existing date and time expressions

As we have previously seen, the DateTime Handler consists of two parts: a DateTime library and a DateTime interpretation script. You may make changes to both components, depending on what you want to change. In order to broaden the coverage of the recognition, you will have to make changes to the DateTime library. If you only want to change the interpretation of an existing date or time expression, you will add a few lines of code to the pre-processing script.

Add variants to be recognized

If you want to adjust the recognition of date or time expressions, this is how to go about:

  1. Identify the language object of the DateTime library that should be adapted. You can find all language objects associated with the DateTime library using Teneo's search interface and the search prefix "DT_*". Make sure to search through "Current solution and its referenced Lexical Resources".
  2. Make a local copy of this language object. Name the new language object identical to its original version.
  3. Go ahead and make the required adjustments to this local copy.
  4. Hit 'Save'.

At runtime, only this locally modified version of the language object will be used, as local language objects always have precedence over the language objects of imported libraries.

Important Note: when editing the local copy make sure to use only existing NLU variables and values. Otherwise, the DateTime interpretation script will not be able to map the representation to date and time expressions.

Change the interpretation of existing expressions

Sometimes the expression you want to change is already coverd by the DateTime Handler, but you are just not happy with its interpretation. For example, how to interpret "lunch" time greatly varies depending on local preferences. Say we want to change the interpretation of "lunch" time from 12:00 to 13:00 in all flows of our solution. This is what we have to do:

  1. In the global pre-processing script, paste datetime.Handler.addNamedTime('lunch', '1300')
  2. Hit 'Save'.
  3. Go back to the main solution window and reload the engine before trying it out.

For the modification of named dates, there is a method called 'addNamedDates'. Say you want to change the interpretation of mother's day (which differs depending on the country), then simply add datetime.Handler.addNamedDate('mothers_day', '2019-05-08') to the pre-processing script. Note that you can this way only change the interpretation of already existing named dates and times of the DateTimeHandler. In the following we will show you how to add new dates and times to the DateTime library and their interpretations.

Add new date and time expressions

The DateTimeHandler comes with a number of pre-defined named dates like "Christmas Day" or "New Year's Eve". However, sometimes you may want to add your own named dates. We will show you here how to go about if you want to add named dates or modify interpretations of existing named dates:

  1. Modify a language object of the DateTime library
  2. Add a line of code to the global Pre-processing script.

Modify the language object

In the following, we will show you how to add the 'Longberry Baristas Day' to the DateTime library:

  1. In the solution, use the search function to find the DT_NAMED.LIST language object in the DateTime Handler. Make sure to search not only in your current solution but also in its 'Referenced Lexical Resources'.
  2. Make a copy of DT_NAMED.LIST and save it in your solution:
    1. Open DT_NAMED.LIST.
    2. Mark the content in the condition field and copy it.
    3. Add a new language object to your solution.
    4. Paste what you have copied to its condition field.
    5. Name this new language object DT_NAMED.LIST. This name must be identical to the language object you have copied the content from. This will ensure that Teneo will use the local copy instead of the original.
  3. Open the local copy of DT_NAMED.LIST in edit mode.
  4. Paste `/ (longberry>>baristas>>day)^{date.named="longberry_baristas_day"} at the bottom of the condition field.
  5. Hit 'Save'.

Modify the Pre-processing script

Longberry Baristas' day is now recognized by the grammar, so now it's time to add an interpretation for it as well:

  1. In the global pre-processing script, paste datetime.Handler.addNamedDate('longberry_baristas_day', '2019-08-14')
  2. Hit 'Save'.
  3. Go back to the main solution window and reload the engine before trying it out.

If you want to define a range, simply pass two dates or two times instead of one. For example, the Longberry Happy Hour lasting from 17:00 to 18:00 is added like this: datetime.Handler.addNamedTime('longberry_happy_hour', '1700', '1800')

Was this page helpful?