Crates.io | suukon |
lib.rs | suukon |
version | 0.2.0 |
source | src |
created_at | 2023-05-09 19:58:22.743562 |
updated_at | 2024-02-22 12:51:12.918165 |
description | Library and CLI for converting numbers between numeral systems. |
homepage | |
repository | https://gitlab.com/pSchwietzer/suukon |
max_upload_size | |
id | 860788 |
size | 293,837 |
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.
The general pattern of the CLI looks like this:
suukon -i <INPUT> -t <TARGET> -s [SETTINGS] -- <NUMBER>
<INPUT>
- Input numeral system<TARGET>
- Target numeral system[SETTINGS]
- Additional settings for the conversion<NUMBER>
- The number to be convertedLet'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 拾弐点参割肆分
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
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.
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.
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)
);
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.
The following numeral systems are currently supported:
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.
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.
This project is licensed under the MIT license. See the LICENSE file for details.