Skip to content

numbers

The community/core/numbers directory contains files for parsing and representing numbers using voice commands in Talon. It includes both prefixed and unprefixed number input, as well as ordinal numbers.

The core logic for parsing numbers is in numbers.py. This file defines functions to:

  • Convert spoken number words (e.g., "one", "twenty", "thousand") to integers.
  • Parse number phrases of mixed scales (e.g. "one million five hundred thousand") into numeric strings.
  • Handle "oh" variants (e.g., "oh five" for "05") and double-digit variants (e.g., "five one" for "51").
  • Parse decimal numbers (e.g., "one dot two three").
  • Parse comma separated number sequences (e.g., "one comma two").
  • Parse colon separated number sequences (e.g., "one colon two").
  • Handle negative numbers (e.g., "negative one").

It exposes several captures, including:

  • digit_string: Parses a sequence of digits as a string.
  • digits: Parses a sequence of digits as an integer.
  • number_string: Parses a number phrase into a string.
  • number: Parses a number phrase into an integer.
  • number_signed_string: Parses a signed number phrase into a string.
  • number_signed: Parses a signed number phrase into an integer.
  • number_prose_with_dot, number_prose_with_comma, number_prose_with_colon: Parses number sequences with dots, commas, or colons.
  • number_prose_unprefixed: Parses a number with or without dot, comma or colon separated sequences into a string.
  • number_prose_prefixed: Parses a number with a "numb" or "numeral" prefix (e.g., "numb one").
  • number_small: Parses an integer between 0 and 99.
  • number_signed_small: Parses a signed integer between -99 and 99.

The file also defines a list of small numbers (number_small) from 0 to 99, including common spoken variants, and a unprefixed_numbers tag.

The file ordinals.py defines lists of ordinal words and provides captures for them. It includes:

  • ordinals: A list of ordinal words (e.g. "first", "second", "twentieth") from 1 to 99.
  • ordinals_small: A list of ordinal words from 1 to 20.
  • ordinals: A capture that returns an ordinal as an integer.
  • ordinals_small: A capture that returns a small ordinal as an integer.

The files numbers_unprefixed.talon and numbers_prefixed.talon provide the Talon bindings for the captures defined in numbers.py. numbers_unprefixed.talon tags the number_prose_unprefixed capture with the user.unprefixed_numbers tag, allowing number prose to be used without a prefix. numbers_prefixed.talon provides a rule for using number_prose_prefixed prefixed with "numb" or "numeral".

In summary, this directory provides a comprehensive system for voice-based number input including both prefixed and unprefixed numbers, ordinal numbers, and support for various number formats.