text2num

Module lang

source
Expand description

Language interpreters and their support data.

See the crate level documentation for an overview of the usage of the builtin languages.

§How to add support for a new language

The idea behind the decoding of numbers in natural language, is to consider that numbers represents a subset of the language that is “simple” and consistent enough to be interpreted like a an arithmetic computer language.

A number expressed in words is then seen as a little program whose interpretation result is either a sequence of digits, if the number is valid, or an error.

The common runtime for all interpretors is the DigitString. It provided the memory and the elementary functions to build a number in base 10 (even if the language to be interpreted counts otherwise). The DigitString is responsible for checking the validity of the constructed number at each step (i.e at each method call).

The intepretor part, which is specific to each language, is built by implementing the LangInterpretor trait, which translate each number word into a sequence of elementary instructions on a DigitString.

A language is just an empty (stateless) type. Everything is provided by implementating the trait.

Look at the source of the builtin languages as examples.

Structs§

Enums§

  • A convenience enum that encapsulates the builtin languages in a single type.
  • Model the Morphological markers that differenciate ordinals or fractions from cardinals, and that must be retained on the digit form.

Traits§