Digits

This module contains the parser that converts the string representation of a sequence of digits into the corresponding sequence of digits. These digits may be in the form of english cardinal representations of numbers, along with some homophones. The digits can be hyphenated or unhyphenated from twenty through ninety-nine. The unhyphenated numbers get joined automatically. The use of unhyphenated numbers introduces ambiguity. For example, “sixty five thousand” could be parsed as “605000” or “65000”. Our parser will output the latter. However, this can be an issue with values such as “sixty five thousand one” which parses as “650001”. This limitation will most likely be acceptable for most multi-digit use cases such as telephone numbers, social security numbers, etc.

spokestack.nlu.parsers.digits.parse(metadata, raw_value)[source]

Digit Parser

Parameters
  • metadata (Dict[str, Any]) – digit slot metadata

  • raw_value (str) – value tagged by the model

Returns

string parsed digits

Return type

(str)

Entity

This module contains the logic to parse entities from NLU results. The entity parser is a pass through for string values to allow custom logic to resolve the entities. For example, the entity can be used as a keyword in a database search.

spokestack.nlu.parsers.entity.parse(metadata, raw_value)[source]

Entity Parser

Parameters
  • metadata (Dict[str, Any]) – metadata for entity slot

  • raw_value (str) – tagged entity

Returns

tagged entity

Return type

(str)

Integer

This module contains the logic to parse integers from NLU results. Integers can be in the form of words (ie. one, two, three) or numbers (ie. 1, 2, 3). Either form will resolve to Python’s built-in ‘int’ type. The metadata must contain a range key containing the minimum and maximum values for the expected integer range. It is important to note the difference between digits and integers. Integers are counting numbers: 2 apples, a table for two. In contrast, digits can be used for sequences of numbers like phone numbers or social security numbers.

spokestack.nlu.parsers.integer.parse(metadata, raw_value)[source]

Integer Parser

Parameters
  • metadata (Dict[str, Any]) – metadata for the integer slot

  • raw_value (str) – value tagged by the model

Returns

integer if parsable, None if invalid

Return type

Union[int, None]

Selset

This module contains the logic to parse selsets from NLU results. Selsets contain a name along with one or more aliases. This allows one to map any of the listed aliases into a single word. For example, if a selset’s name is “light”, and its aliases are bulbs, light, beam, lamp, etc., occurrences of any alias will be parsed as light

spokestack.nlu.parsers.selset.parse(metadata, raw_value)[source]

Selset Parser

Parameters
  • metadata (Dict[str, Any]) – slot metadata

  • raw_value (str) – value tagged by the model

Returns

selset or None if invalid

Return type

Union[str, None]