Teneo Developers

Share to

Unit Conversions

The Unit Conversion solution holds a flow that converts units of area, length, mass, speed, temperature, time, volume from one system to another.

unit conversion

The flow uses a conditional trigger, which in turn uses a listener to record the source and destination units of meeasurement for the conversions, as well as the number/amount of source units to convert.

The user is prompted in case any of the required values are missing, which are then picked up by transition listeners. Once the conversion parameters are known, the flow uses a groovy map to determine the conversion factor and then performs the conversion, subsequently displaying the result. The flow also includes error detection: in case of incompatible conversion types, e.g. liters to miles, the flow warns the user about the mistake.

Core concepts

  • Slot filling
  • Number recognition
  • Groovy annotation resource
  • Listeners

Example conversations

User: Can you convert 50 meters?
Bot: What did you want to convert meters to?

User: yards
Bot: A length of 50.0 meters is equivalent to 54.7 yards.

User: How many miles is 100km?
Bot: A distance of 100.0 kilometers is equivalent to 62.15 miles.

User: convert gallons to liters
Bot: A volume of 1.0 liter is equivalent to .26 gallons.

User: How much is 6 feet 5 inches in centimeters?
Bot: A length of 6 feet and 5 inches is equivalent to 195.58 centimeters.

User: How many hours are in half a day
Bot: A duration of 0.5 days is equivalent to 12.0 hours.

User: Can you convert meters?
Bot: What did you want to convert meters to?

User: 3 feet
Bot: A length of 3 feet is equivalent to .91 meters.

Solution components

This solution contains the following components:

NameTypeDescription
Unit ConversionFolderFolder that holds subfolders for the flows and language objects in this solution.
Unit conversionsFlowA self-contained slot filling flow. Allows user to specify a unit to convert from, unit to convert to and an optional amount. Stored in the Unit Conversion > Flows folder.
convertArea, convertLength, convertMass, convertLength, convertSpeed, convertTime, convertVolumeFlow variablesThese are groovy maps containing the conversion factors need to convert from a source unit to a destination unit. The units of measure are used as keys to retrieve the associated multiplication factor. Note that temperature is not covered here, as these conversions are based on specific formulas.
UNITS.ENTITYEntityEntity to retrieve units to convert to and from.
DEGREES_CELSIUS.NN.SYN, DEGREES_FAHRENHEIT.NN.SYN, FLUID_OUNCE.NN.SYN, METER.NN.SYNLanguage objectsThese language objects are used in UNITS.ENTITY to enable more robust recognition of the units in question, over and above the Teneo Language Resources.
VALUE_UNITS.ENTITYEntitySecondary entity to retrieve values and units written together, e.g. 100m.
VALUE_ACRES.NN.SYN ... VALUE_YEARS.NN.SYNLanguage objectsSupport language objects for all the units covered in VALUE_UNITS.ENTITY (30 in all). They contain a value and unit written as one token and are used to parse the value and unit back into individual parts.
RegAnnotHelper.groovyFile resourceGroovy script called in a global listener to annotate [value][unit] tokens, such as 20km. If you import this solution into a solution that already contains a resource with the same name, it will add the new resource at the end. Be sure to remove duplicate resources.
Unit Conversion Syntax TriggersOrder GroupThis is an order group for syntax triggers used by the solution. After import you may want to move this above other order groups in your solution to give it priority.

Make sure you check for possible conflicts before you import this solution into an existing solution (merge solutions).

Download

  1. Download the solution here.
  2. Import the solution into Teneo studio. See How to import solutions for more details.
  3. Once the solution has been imported, please make sure to assign the Lexical Resources called 'Teneo Lexical Resource English'.