Skip to content
Commits on Source (74)
[package]
name = "anslatortray"
version = "0.3.0"
version = "0.5.0"
description = "A simple Rust library to translate from English to Pig Latin!"
authors = ["John Zacarias Jekel <john@jekel.ca>"]
readme = "README.md"
......@@ -11,28 +11,21 @@ license = "MIT"
edition = "2021"
keywords = ["pig", "latin", "text", "translate", "translator"]
categories = ["text-processing", "command-line-utilities", "localization"]
default-run = "anslatetray"
default-run = "anslatortray"
documentation = "https://docs.rs/anslatortray/latest/anslatortray/"
[features]
default = []
nightly-features = []
nightly-features = ["nightly-features-benches"]
nightly-features-benches = []
[lib]
name = "anslatortray"
path = "src/lib.rs"
[[bin]]
name = "anslatetray"
path = "src/anslatetray.rs"
[[bin]]
name = "anslatetray-file"
path = "src/anslatetray-file.rs"
#[features]
#default = ["default_style_way"]
#default_style_way = []
#default_style_yay = []
name = "anslatortray"
path = "src/anslatortray.rs"
[profile.dev]
incremental = true
......
# anslatortray-rs
# Anslatortray for Rust
A simple Rust library to translate from English to Pig Latin!
......@@ -6,116 +6,103 @@ A simple Rust library to translate from English to Pig Latin!
Essentially, the word is reorganized in an effort to hide its true meaning, which can be lots of fun!
The Anslatortray library can help out by converting any English text into Pig Latin quickly and easily. It is incredibly fast (see the Performance section below) and requires no dependencies!
# A Quick Example
You can translate multiple sentences, including numbers, punctuation, and spacing, with a single call to `anslatortray::translate()`.
The function handles edge cases quite well (words without vowels, one-letter words, contractions, etc.), though there is always room for improvement.
If you have suggestions for how the project could be improved, please visit the repository's issues page on <a href="https://github.com/JZJisawesome/anslatortray-rs/issues">Github</a> or <a href="https://gitlab.com/JZJisawesome/anslatortray-rs/-/issues">GitLab</a> or contact me directly :)
Be sure to check out the documentation at <https://docs.rs/anslatortray/latest/anslatortray/>!
# Library Examples
After adding Anslatortray as a dependency in your crate, try compiling this example code:
Try compiling this example code:
```
```rust
use anslatortray::translate;
fn main() {
//Prints "Ellohay orldway omfray ethay Anslatortray orfay Ustray!"
println!("{}", translate("Hello world from the Translator for Rust!"));
}
```
Anslatortray also supports using the "yay" suffix instead in special cases if you prefer that:
# Tell me more!
```
use anslatortray::translate_yay;
The Anslatortray library can help out by converting any English text into Pig Latin quickly and easily. It is **incredibly fast** (see the Performance section below) and **requires no dependencies**!
//Prints "Utbay Iyay eferpray ethay ayyay-ylestay igpay atinlay!"
println!("{}", translate_yay("But I prefer the yay-style pig latin!"));
```
You can translate multiple sentences, including numbers, punctuation, and spacing, with a single call to `anslatortray::translate()`.
The function handles edge cases quite well (words without vowels, one-letter words, contractions, ALL CAPS, etc.), though there is always room for improvement.
It also supports Ferb Latin from Phineas and Ferb:
If you have suggestions for how the project could be improved, please visit the repository's issues page on <a href="https://github.com/JZJisawesome/anslatortray-rs/issues">Github</a> or <a href="https://gitlab.com/JZJisawesome/anslatortray-rs/-/issues">GitLab</a> or contact me directly :)
```
use anslatortray::translate_ferb;
Be sure to check out the documentation at <https://docs.rs/anslatortray/latest/anslatortray/>!
//Prints "Erewherb's Erryperb?"
println!("{}", translate_ferb("Where's Perry?"));
```
# Building and Installation
If none of these suit your needs, you can also choose your own suffixes with `anslatortray::translate_with_style()`
If you wish to use the library in your crate, add anslatortray as a dependency and <a href="https://docs.rs/anslatortray/latest/anslatortray/">check out the documentation</a>.
# Included Programs Example Usage
If you wish to use the `anslatortray` standalone binary (shown in the next section), clone `https://git.jekel.ca/JZJ/anslatortray.git`, do `cargo build --release`, and you'll find the binary in the target/release directory.
## anslatetray
See the <a href="https://git.jekel.ca/JZJ/anslatortray-rs/wiki/Building-And-Installing">wiki</a> for more information.
Translates command line arguments passed to it
# anslatortray CLI Tool Usage
There are several options supported by the `anslatortray` command:
```
> anslatetray
Error: expected at least one string to translate
> anslatetray Hello World!
Ellohay Orldway!
> anslatetray A simple Rust library to translate from English to Pig Latin!
Away implesay Ustray ibrarylay otay anslatetray omfray Englishway otay Igpay Atinlay!
> anslatortray --help
Anslatortray: frontend for the Anslatortray for Rust library
Options:
--help Print this helpful text!
--interactive Start an interactive translation session
--file Translate a file (requires two arguments, the file to translate and the destination)
--benchmark-file Benchmark translating a file (requires two arguments, the file to translate and the number of iterations to perform)
--translate-args Translates all remaining arguments provided and outputs them to stdout
--stdin-to-stdout Translates input from stdin directly to stdout
Avehay away oodgay ayday!
```
## anslatetray-file
Translates an input file and writes the results to an output file
You can start an interactive session by specifying --interactive (or no arguments at all):
```
> anslatetray-file
Error: expected two arguments, the input file to be translated and the file to output the translated text to
> anslatetray-file input_but_no_output_file_specified.txt
Error: expected two arguments, the input file to be translated and the file to output the translated text to
> anslatetray-file words_alpha.txt words_alpha_pig_latin.txt
Sucessful: took 90144337ns to translate
```
> anslatortray --interactive
Anslatortray: frontend for the Anslatortray for Rust library
The last example uses words_alpha.txt from <https://github.com/dwyl/english-words>. See below for more information.
Starting interactive mode!
Type what you'd like to translate and then press enter, or press Ctrl+C to exit...
# Performance
anslatortray> The fitness gram pacer test is a multi-stage areobic endurance test that...
Ethay itnessfay amgray acerpay esttay isway away ultimay-agestay areobicway enduranceway esttay atthay...
On my dated system with dual Intel(R) Xeon(R) E5-2670 v2 CPUs, the `translate()` function can process one word every 227.462 nanoseconds on average.
I tested this by feeding the words_alpha.txt file from <https://github.com/dwyl/english-words> to anslatetray-file 10 times, calculating the average runtime,
and dividing by 370105 (the number of words in the file). The times do not including loading from and writing to the disk.
anslatortray> ^C
>
```
Note that raw calls to `translate_word()` would be faster, but `translate()` has to be smart enough to preserve symbols and whitespace surrounding each word, while still accounting for contractions and other edge-cases.
You can also pipe text into the command for use in scripting:
```
> for run in {1..10}; do anslatetray-file words_alpha.txt words_alpha_pig_latin.txt; done
Sucessful: took 90144337ns to translate
Sucessful: took 82581222ns to translate
Sucessful: took 82803035ns to translate
Sucessful: took 80643452ns to translate
Sucessful: took 80542962ns to translate
Sucessful: took 81848295ns to translate
Sucessful: took 81600103ns to translate
Sucessful: took 86463460ns to translate
Sucessful: took 87399299ns to translate
Sucessful: took 87821022ns to translate
> echo "Testing pipes" | anslatortray --stdin-to-stdout > test_pipes.txt
Anslatortray: frontend for the Anslatortray for Rust library
> cat test_pipes.txt
Estingtay ipespay
```
There are also some benchmarks built into the library that you can run to easily check the performance of it on your system:
If you'd like, you can even translate a text file:
```
> cargo bench --features nightly-features
[...]
test translate_strings::benches::translate_ferb_lorem_ipsum ... bench: 11,284 ns/iter (+/- 331)
test translate_strings::benches::translate_ferb_project_description ... bench: 1,852 ns/iter (+/- 28)
test translate_strings::benches::translate_lorem_ipsum ... bench: 11,033 ns/iter (+/- 284)
test translate_strings::benches::translate_project_description ... bench: 1,848 ns/iter (+/- 61)
test translate_strings::benches::translate_yay_lorem_ipsum ... bench: 10,968 ns/iter (+/- 263)
test translate_strings::benches::translate_yay_project_description ... bench: 1,809 ns/iter (+/- 40)
test translate_words::benches::translate_word_ferb_the_word_translator ... bench: 120 ns/iter (+/- 3)
test translate_words::benches::translate_word_the_word_translator ... bench: 126 ns/iter (+/- 7)
test translate_words::benches::translate_word_yay_the_word_translator ... bench: 121 ns/iter (+/- 6)
[...]
> echo "Test file" > test_file.txt && cat test_file.txt
Test file
> anslatortray --file test_file.txt output_file.txt
Anslatortray: frontend for the Anslatortray for Rust library
Sucessful: took 3540ns to translate
> cat output_file.txt
Esttay ilefay
```
Anslatortray is quite fast, but it could be faster :). Both the speed and the quality of translation are priorities for me, and I'm working to improve them both!
See <a href="https://git.jekel.ca/JZJ/anslatortray-rs/wiki/Using-the-anslatortray-binary">this wiki page</a> for more!
# Performance
Check out the <a href="https://git.jekel.ca/JZJ/anslatortray-rs/wiki/Performance">wiki page about Anslatortray's performance</a>!
Spoiler: `anslatortray::translate()` can process one word in under **50ns** on average!
# Useful Links
......@@ -123,7 +110,7 @@ Anslatortray is quite fast, but it could be faster :). Both the speed and the qu
You can also visit the <a href="https://github.com/JZJisawesome/anslatortray-rs/issues">Github</a> or <a href="https://gitlab.com/JZJisawesome/anslatortray-rs/-/issues">GitLab</a> mirrors to leave issues!
Be sure to check out the documentation at <https://docs.rs/anslatortray/latest/anslatortray/>!
Be sure to check out the documentation at <https://docs.rs/anslatortray/latest/anslatortray/> and the wiki at <https://git.jekel.ca/JZJ/anslatortray-rs/wiki>.
Anslatortray for Rust is a spiritual sucessor of my original <a href="https://git.jekel.ca/JZJ/anslatortray">Anslatortray</a> (for C++).
......@@ -133,12 +120,6 @@ None other than the standard libraries!
# Anslatortray Code and Documentation Licence
MIT License
Copyright (c) 2022 John Jekel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT Licensed (see the LICENSE file for details)
/* anslatetray-file
* Copyright (C) 2022 John Jekel
* See the LICENSE file at the root of the project for licensing info.
*
* Frontend to translate a file
*
*/
/* Imports */
use anslatortray::translate;
/* Functions */
fn main() {
eprintln!("Note: anslatetray-file is highly experimental and has poor error handling. You have been warned.");
//Get all arguments after the executable's name
let args: Vec<String> = std::env::args().collect();
if args.len() != 3 {
eprintln!("Error: expected two arguments, the input file to be translated and the file to output the translated text to");
return;
}
//TODO error handling
//TODO preserve file formatting better
let input_file = std::env::args().nth(1).unwrap();
let output_file = std::env::args().nth(2).unwrap();
let file_contents = std::fs::read_to_string(input_file).unwrap();
let start_time = std::time::Instant::now();
let translated_file_contents = translate(&file_contents);
let time_to_translate = start_time.elapsed();
std::fs::write(output_file, &translated_file_contents).unwrap();
eprintln!("Sucessful: took {}ns to translate", time_to_translate.as_nanos());
}
/* anslatetray
* Copyright (C) 2022 John Jekel
* See the LICENSE file at the root of the project for licensing info.
*
* Simple command-line frontend for the Anslatortray for Rust
*
*/
/* Imports */
use anslatortray::translate;
/* Functions */
fn main() {
//Get all arguments after the executable's name
let mut args: Vec<String> = std::env::args().collect();
if args.len() < 2 {
eprintln!("Error: expected at least one string to translate");
return;
}
args.remove(0);
//Translate the arguments and print them out for the user
for string in args {
print!("{} ", translate(&string));
}
println!();
}
/* anslatortray
* Copyright (C) 2022 John Jekel
* See the LICENSE file at the root of the project for licensing info.
*
* Command-line frontend for the anslatortray library
*
*/
/* Imports */
use anslatortray::translate;
use anslatortray::byte_string;
/* Functions */
fn main() {
eprintln!("Anslatortray: frontend for the Anslatortray for Rust library\n");
//Get all arguments after the executable's name
let mut args: Vec<String> = std::env::args().collect();
args.remove(0);
if args.len() == 0 {
interactive(&args);
return;
}
let option = args[0].clone();
args.remove(0);
match option.as_str() {
"--help" => { help(); },
"--interactive" => { interactive(&args); },
"--file" => { file(&args); },
"--benchmark-file" => { benchmark_file(&args); },
"--translate-args" => { translate_args(&args); },
"--stdin-to-stdout" => { stdin_to_stdout(&args); },
bad_option => {
eprintln!("Error: {} is not a valid option", bad_option);
help();
}
}
}
fn help() {
eprintln!("Options:");
eprintln!("--help Print this helpful text!");
eprintln!("--interactive Start an interactive translation session");
eprintln!("--file Translate a file (requires two arguments, the file to translate and the destination)");
eprintln!("--benchmark-file Benchmark translating a file (requires two arguments, the file to translate and the number of iterations to perform)");
eprintln!("--translate-args Translates all remaining arguments provided and outputs them to stdout");
eprintln!("--stdin-to-stdout Translates input from stdin directly to stdout");
eprintln!("\n{}", translate("Have a good day!"));
}
fn interactive(args: &Vec<String>) {
if args.len() != 0 {
eprintln!("Error: didn't expect any arguments");
help();
return;
}
eprintln!("Starting interactive mode!");
eprintln!("Type what you'd like to translate and then press enter, or press Ctrl+C to exit...\n");
let stdin = std::io::stdin();
let mut line_buffer = String::new();
loop {
eprint!("anslatortray> ");
stdin.read_line(&mut line_buffer).unwrap();
eprintln!("{}", translate(&line_buffer));
line_buffer.truncate(0);
}
}
fn file(args: &Vec<String>) {
eprintln!("Note: anslatortray --file is highly experimental and has poor error handling. You have been warned.");
if args.len() != 2 {
eprintln!("Error: expected two arguments, two arguments, the file to translate and the destination");
help();
return;
}
//TODO error handling
//TODO switch to using byte_string for efficiency
let input_file = &args[0];
let output_file = &args[1];
let file_contents = std::fs::read_to_string(input_file).unwrap();
let start_time = std::time::Instant::now();
let translated_file_contents = translate(&file_contents);
let time_to_translate = start_time.elapsed();
std::fs::write(output_file, &translated_file_contents).unwrap();
eprintln!("Sucessful: took {}ns to translate", time_to_translate.as_nanos());
}
fn benchmark_file(args: &Vec<String>) {
eprintln!("Note: anslatortray --benchmark-file is highly experimental and has poor error handling. You have been warned.");
if args.len() != 2 {
eprintln!("Error: expected two arguments, the file to translate and the number of iterations to perform");
help();
return;
}
//TODO error handling
let input_file = &args[0];
let iterations = args[1].parse::<u128>().unwrap();//TODO error handling
let file_contents = std::fs::read_to_string(input_file).unwrap();
let mut total_duration_regular = std::time::Duration::new(0, 0);
for _ in 0..iterations {
let start_time = std::time::Instant::now();
let translated_file_contents = translate(&file_contents);
let time_to_translate = start_time.elapsed();
total_duration_regular += time_to_translate;
std::fs::write("/dev/null", &translated_file_contents).unwrap();//TODO avoid needing unix
}
eprintln!("Sucessful: Regular translation took {}ns to translate on average over {} runs.", total_duration_regular.as_nanos() / iterations, iterations);
let mut total_duration_byte_string = std::time::Duration::new(0, 0);
let mut translated_file_contents = Vec::<u8>::new();//TODO set a sane initial size
for _ in 0..iterations {
let start_time = std::time::Instant::now();
translated_file_contents.truncate(0);
byte_string::translate(file_contents.as_bytes(), &mut translated_file_contents);
let time_to_translate = start_time.elapsed();
total_duration_byte_string += time_to_translate;
std::fs::write("/dev/null", &translated_file_contents).unwrap();//TODO avoid needing unix
}
eprintln!("Sucessful: Byte-string translation with reused allocations took {}ns to translate on average over {} runs.", total_duration_byte_string.as_nanos() / iterations, iterations);
}
fn translate_args(args: &Vec<String>) {
if args.len() == 0 {
eprintln!("Error: expected at least one string to translate");
help();
return;
}
//Translate the arguments and print them out for the user
for string in args {
print!("{} ", translate(&string));
}
println!();
}
fn stdin_to_stdout(args: &Vec<String>) {
use std::io::{Read, Write};
if args.len() != 0 {
eprintln!("Error: didn't expect any arguments");
help();
return;
}
let mut stdin = std::io::stdin();
let mut stdout = std::io::stdout();
let mut buffer = String::new();
while let Ok(bytes_read) = stdin.read_to_string(&mut buffer) {
if bytes_read == 0 { return; }
write!(stdout, "{}", translate(&buffer)).unwrap();//TODO do this more efficiently (avoid format string)
buffer.truncate(0);//TODO is this needed here?
}
}
This diff is collapsed.
/* helpers.rs
* Copyright (C) 2022 John Jekel
* See the LICENSE file at the root of the project for licensing info.
*
* Contains helper functions for translate_words.rs
*
*/
/* Functions */
///Returns whether a letter is a vowel or not.
///
///If the parameter is a letter, returns Some(true) if it is a vowel, and Some(false) otherwise.
///If the parameter isn't a letter, it will return None
///
///This is a helper function used by [`translate_word()`](crate::translate_word), but
///it is publically exposed as potential users may find this useful.
///
///# Examples
///
///```
///for letter in "aeiouAEIOU".chars() {
/// assert!(anslatortray::is_vowel(letter).unwrap());
///}
///
///for letter in "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ".chars() {
/// assert!(!anslatortray::is_vowel(letter).unwrap());
///}
///
///for not_letter in " !@#$%^&*()_+={}|\":>?~`\\][';/.,".chars() {
/// assert!(matches!(anslatortray::is_vowel(not_letter), None));
///}
///```
pub fn is_vowel(letter: char) -> Option<bool> {
if !letter.is_alphabetic() {
return None;
}
match letter.to_ascii_lowercase() {
'a' | 'e' | 'i' | 'o' | 'u' => { return Some(true); }
_ => { return Some(false); }
}
}
///Returns whether a letter is y or not.
///
///If the parameter is a letter, returns Some(true) if it is y, and Some(false) otherwise.
///If the parameter isn't a letter, it will return None
///
///This is a helper function used by [`translate_word()`](crate::translate_word), but
///it is publically exposed as potential users may find this useful.
///
///# Examples
///
///```
///for letter in "yY".chars() {
/// assert!(anslatortray::is_y(letter).unwrap());
///}
///
///for letter in "abcdefghijklmnopqrstuvwxzABCDEFGHIJKLMNOPQRSTUVWXZ".chars() {
/// assert!(!anslatortray::is_y(letter).unwrap());
///}
///
///for not_letter in " !@#$%^&*()_+={}|\":>?~`\\][';/.,\t\n".chars() {
/// assert!(matches!(anslatortray::is_y(not_letter), None));
///}
///```
pub fn is_y(letter: char) -> Option<bool> {
if !letter.is_alphabetic() {
return None;
}
return Some(letter.to_ascii_lowercase() == 'y');
}
/* Tests */
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_vowel() {
for letter in "aeiouAEIOU".chars() {
assert!(is_vowel(letter).unwrap());
}
for letter in "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ".chars() {
assert!(!is_vowel(letter).unwrap());
}
for not_letter in " !@#$%^&*()_+={}|\":>?~`\\][';/.,\t\n".chars() {
assert!(matches!(is_vowel(not_letter), None));
}
}
#[test]
fn test_is_y() {
for letter in "yY".chars() {
assert!(is_y(letter).unwrap());
}
for letter in "abcdefghijklmnopqrstuvwxzABCDEFGHIJKLMNOPQRSTUVWXZ".chars() {
assert!(!is_y(letter).unwrap());
}
for not_letter in " !@#$%^&*()_+={}|\":>?~`\\][';/.,\t\n".chars() {
assert!(matches!(is_y(not_letter), None));
}
}
}
//!Anslatortray for Rust
//!Anslatortray for Rust: A simple Rust library to translate from English to Pig Latin.
//!
//!Welcome to the Anslatortray Documentation!
//!
//!A simple Rust library to translate from English to Pig Latin.
//!# Building and Installation
//!
//!If you wish to use the library in your crate, add anslatortray as a dependency and follow along with the examples below, or check out the rest of the documentation.
//!
//!<a href="https://en.wikipedia.org/wiki/Pig_Latin">Wikipedia's definition of Pig Latin</a> is "a language game or argot in which words in English are altered, usually by adding a fabricated suffix or by moving the onset or initial consonant or consonant cluster of a word to the end of the word and adding a vocalic syllable to create such a suffix."
//!
//!Essentially, the word is reorganized in an effort to hide its true meaning, which can be lots of fun!
//!
//!The Anslatortray library can help out by converting any English text into Pig Latin quickly and easily. It is incredibly fast (see the Performance section below) and requires no dependencies!
//!
//!You can translate multiple sentences, including numbers, punctuation, and spacing, with a single call to [`translate()`].
//!The function handles edge cases quite well (words without vowels, one-letter words, contractions, etc.), though there is always room for improvement.
//!
//!If you have suggestions for how the project could be improved, please visit the repository's issues page on <a href="https://github.com/JZJisawesome/anslatortray-rs/issues">Github</a> or <a href="https://gitlab.com/JZJisawesome/anslatortray-rs/-/issues">GitLab</a> or contact me directly :)
//!
//!Be sure to check out the documentation at <https://docs.rs/anslatortray/latest/anslatortray/>!
//!See the <a href="https://git.jekel.ca/JZJ/anslatortray-rs/wiki/Building-And-Installing">wiki</a> for more information.
//!
//!# Library Examples
//!
......@@ -49,83 +39,14 @@
//!
//!If none of these suit your needs, you can also choose your own suffixes with [`translate_with_style()`]
//!
//!# Included Programs Example Usage
//!
//!## anslatetray
//!
//!Translates command line arguments passed to it
//!
//!```text
//!> anslatetray
//!Error: expected at least one string to translate
//!> anslatetray Hello World!
//!Ellohay Orldway!
//!> anslatetray A simple Rust library to translate from English to Pig Latin!
//!Away implesay Ustray ibrarylay otay anslatetray omfray Englishway otay Igpay Atinlay!
//!```
//!
//!## anslatetray-file
//!
//!Translates an input file and writes the results to an output file
//!
//!```text
//!> anslatetray-file
//!Error: expected two arguments, the input file to be translated and the file to output the translated text to
//!> anslatetray-file input_but_no_output_file_specified.txt
//!Error: expected two arguments, the input file to be translated and the file to output the translated text to
//!> anslatetray-file words_alpha.txt words_alpha_pig_latin.txt
//!Sucessful: took 62204293ns to translate
//!```
//!
//!The last example uses words_alpha.txt from <https://github.com/dwyl/english-words>. See below for more information.
//!
//!# Performance
//!
//!On my dated system with dual Intel(R) Xeon(R) E5-2670 v2 CPUs, the `translate()` function can process one word every 227.462 nanoseconds on average.
//!I tested this by feeding the words_alpha.txt file from <https://github.com/dwyl/english-words> to anslatetray-file 10 times, calculating the average runtime,
//!and dividing by 370105 (the number of words in the file). The times do not including loading from and writing to the disk.
//!
//!Note that raw calls to `translate_word()` would be faster, but `translate()` has to be smart enough to preserve symbols and whitespace surrounding each word, while still accounting for contractions and other edge-cases.
//!
//!```text
//!> for run in {1..10}; do anslatetray-file words_alpha.txt words_alpha_pig_latin.txt; done
//!Sucessful: took 90144337ns to translate
//!Sucessful: took 82581222ns to translate
//!Sucessful: took 82803035ns to translate
//!Sucessful: took 80643452ns to translate
//!Sucessful: took 80542962ns to translate
//!Sucessful: took 81848295ns to translate
//!Sucessful: took 81600103ns to translate
//!Sucessful: took 86463460ns to translate
//!Sucessful: took 87399299ns to translate
//!Sucessful: took 87821022ns to translate
//!```
//!
//!There are also some benchmarks built into the library that you can run to easily check the performance of it on your system:
//!
//!```text
//!> cargo bench --features nightly-features
//![...]
//!test translate_strings::benches::translate_ferb_lorem_ipsum ... bench: 11,284 ns/iter (+/- 331)
//!test translate_strings::benches::translate_ferb_project_description ... bench: 1,852 ns/iter (+/- 28)
//!test translate_strings::benches::translate_lorem_ipsum ... bench: 11,033 ns/iter (+/- 284)
//!test translate_strings::benches::translate_project_description ... bench: 1,848 ns/iter (+/- 61)
//!test translate_strings::benches::translate_yay_lorem_ipsum ... bench: 10,968 ns/iter (+/- 263)
//!test translate_strings::benches::translate_yay_project_description ... bench: 1,809 ns/iter (+/- 40)
//!test translate_words::benches::translate_word_ferb_the_word_translator ... bench: 120 ns/iter (+/- 3)
//!test translate_words::benches::translate_word_the_word_translator ... bench: 126 ns/iter (+/- 7)
//!test translate_words::benches::translate_word_yay_the_word_translator ... bench: 121 ns/iter (+/- 6)
//![...]
//!```
//!
//!Anslatortray is quite fast, but it could be faster :). Both the speed and the quality of translation are priorities for me, and I'm working to improve them both!
//!If you want even more speed than the regular translation functions bring to the table, check out the [`byte_string`] module.
//!
//!# Useful Links
//!<a href="https://git.jekel.ca/JZJ/anslatortray-rs">Click here to visit the Anslatortray for Rust Git Repository!</a>.
//!
//!You can also visit the <a href="https://github.com/JZJisawesome/anslatortray-rs/issues">Github</a> or <a href="https://gitlab.com/JZJisawesome/anslatortray-rs/-/issues">GitLab</a> mirrors to leave issues!
//!
//!Be sure to check out the documentation at <https://docs.rs/anslatortray/latest/anslatortray/>!
//!Be sure to check out the <a href="https://crates.io/crates/anslatortray">crates.io page</a> and the wiki at <https://git.jekel.ca/JZJ/anslatortray-rs/wiki>.
//!
//!Anslatortray for Rust is a spiritual sucessor of my original <a href="https://git.jekel.ca/JZJ/anslatortray">Anslatortray</a> (for C++).
//!
......@@ -134,26 +55,19 @@
//!None other than the standard libraries!
//!
//!# Anslatortray Code and Documentation Licence
//!MIT License
//!
//!Copyright (c) 2022 John Jekel
//!
//!Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//!
//!The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//!
//!THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//!MIT Licensed (see the LICENSE file for details)
/* Nightly Features */
//Only enabled if the relevant Cargo feature is
#![cfg_attr(feature = "nightly-features", feature(test))]
#![cfg_attr(feature = "nightly-features-benches", feature(test))]
/* Imports */
mod helpers;
mod translate_strings;
mod translate_words;
pub mod byte_string;
mod string;
pub use helpers::{is_vowel, is_y};
pub use translate_strings::{translate, translate_way, translate_yay, translate_ferb, translate_with_style};
pub use translate_words::{translate_word, translate_word_way, translate_word_yay, translate_word_ferb, translate_word_with_style};
pub use string::{translate, translate_way, translate_yay, translate_hay, translate_ferb, translate_with_style};
This diff is collapsed.