#numeral #finance #cli #pattern-matching #numeral-systems

bin+lib suukon

Library and CLI for converting numbers between numeral systems

2 unstable releases

0.2.0 Feb 22, 2024
0.1.0 May 9, 2023

#579 in Command line utilities

21 downloads per month

MIT license

275KB
4K SLoC

SUUKON | 数コン

Warning: Breaking changes have been introduced in this update. If you've been using v0.1.0, please check the changelog for more details.

This Rust crate provides a CLI binary and a library for working with multiple numeral systems.

The library includes a trait called Numeral for ergonomic use and a set of modules for each numeral system which offer more direct control.

The main goal of this crate is, to support any kind of numeral system. For reference of numeral systems, please check the list of numeral systems on Wikipedia.

Command-Line Interface

The general pattern of the CLI looks like this:

suukon -i <INPUT> -t <TARGET> -s [SETTINGS] -- <NUMBER>

Reference

  • <INPUT> - Input numeral system
  • <TARGET> - Target numeral system
  • [SETTINGS] - Additional settings for the conversion
  • <NUMBER> - The number to be converted

Example

Let's say, you want to convert a regular number to a japanese number using 大字だいじ numerals with negative powers of ten which start with instead of . The command would look like this:

suukon -t japanese -s financial negative_powers alt -- 12.34

When converting back you won't need to set settings, since the algorithms do the necessary pattern matching for you:

suukon -i japanese 拾弐点参割肆分

Help

For reference of available settings to use, please check the documentation on crates.io.

To see a full list of available flags simply use this command:

suukon --help

Installation

Simply add the following line to your Cargo.toml:

[dependencies]
suukon = { version = "0.2.0", default-features = false }

Or install the binary locally:

cargo install suukon

This will download the latest version of the suukon crate from crates.io and compile the binary.

Usage

There are generally two ways to use this crate in your project. For more ergonomic usage, using the Numeral trait is recommended, but you can still use the regular functions.

Numeral Trait

Additionally to importing the Numeral trait you will need to import the NumeralSystem and Setting enums.

use suukon::{Numeral, NumeralSystem, Setting};

// Convert a number to japanese short notation
assert_eq!(
    Some("12.3万".to_string()),
    123000.to_numeral(
        NumeralSystem::Japanese,
        vec![Setting::ShortNotation]
    )
);

// Convert a number back
assert_eq!(
    Some("123000".to_string()),
    "12.3万".from_numeral(NumeralSystem::Japanese)
);

Regular functions

Alternatively you can import the individual module of an numeral system and use the functions it provides.

use suukon::japanese::*;

For more details on how to use the regular functions, please look at the documentation on crates.io.

Supported Numeral Systems

The following numeral systems are currently supported:

Potential Use Case

By generating training data from this library, language models can learn to recognize and work with different numeral systems, which can improve the accuracy of translations.

Contributing

If you encounter any bugs or issues with this library, please open an issue on the GitLab repository.

If you would like to contribute to the development of Suukon, you can submit a merge request on the GitLab repository. Please ensure that your merge requests includes relevant tests.

Please check CONTRIBUTING.md for more info on how to contribute.

License

This project is licensed under the MIT license. See the LICENSE file for details.

Dependencies

~390–770KB
~15K SLoC