Skip to main content

Crate words2num2_core

Crate words2num2_core 

Source
Expand description

Pure-Rust core for words2num2 — the inverse of num2words2.

§Why this is small

119 of words2num2’s 120 locales never had a hand-written parser. They use Words2Num_Base, which materialises a reverse lookup table by calling num2words across LOOKUP_RANGE (range(-1, 10001)) — 10,002 renders — and then does a dict hit. Only en is hand-written.

So the port is: the generic table backend + _normalize + the en grammar parser. The table is built by calling the Rust num2words core (num2words2-core) directly, which is where the speedup comes from.

This crate has no PyO3 dependency: it is the pure-Rust engine. The words2num2-py crate is a thin PyO3 binder over the public API here.

Re-exports§

pub use w2n_sentence::words2num;

Modules§

w2n_formats
Port of words2num2/formats.py — per-locale number-format defaults and the configurable numeric-string parser.
w2n_lang_en
Port of words2num2/words2num2/lang_EN.py — the Words2Num_EN grammar.
w2n_sentence
Port of the words2num2 sentence-level API.

Enums§

LookupError
Error from the reverse-table backend.

Functions§

en_to_cardinal
Words2Num_EN().to_cardinal(text).
en_to_ordinal
Words2Num_EN().to_ordinal(text).
en_to_year
Words2Num_EN().to_year(text).
lookup
Port of Words2Num_Base._lookup + to_cardinal/to_ordinal.
normalize
Pure-Rust port of Words2Num_Base._normalize.
normalize_tail
Port of the tail of Words2Num_Base._normalize — the pure ASCII-shaped rewriting that follows NFKD decomposition + combining-mark stripping.
parse_int
Port of _rust.parse_int — a plain int(s) for a signed ASCII integer.
supported_langs
Languages the Rust core can serve (Python’s _RUST.supported_langs()).