Crates.io | zoea |
lib.rs | zoea |
version | 0.1.0 |
source | src |
created_at | 2020-05-12 02:40:05.284916 |
updated_at | 2021-05-14 20:51:33.660465 |
description | Zoea is a crate by and for baby Rustaceans. It contains 'easy' buttons for common things like http get requests, key-value database persistence, and Natural Language Processing. |
homepage | |
repository | https://github.com/FabioMencoboni/zoea |
max_upload_size | |
id | 240411 |
size | 21,591 |
What do you call a baby crab? That's right! you call it a Zoea. Zoea is a package for baby Rustaceans, by a baby Rustacean.
Maybe coding is only a part-time thing for you. Maybe you have learned Python and want to try Rust because you heard all the hype. But then after spending two hours trying to make a simple http request and read the response you think "!$!@$!@# it- Rust is too hard."
If you have felt this way, zoea is for you.
zoea does many different things, favoring ergonimics and simplicity over robustness and flexability. It helps you build something, achieve "proof of concept", and then mature into a more natively Rustacean approach. The only common thread between the various modules in zoea is they are all things the author has struggled with or tried to implement.
The get_url functionality has been changed under the hood to use ureq instead of curl. This is a more pure-rust approach vs heritage C code. The method has also had an error wrapper applied.
use zoea::web::get_url;
fn main() {
let url: String = String::from("http://dummy.restapiexample.com/api/v1/employees"); // can be &str or &String
let resp_str: String = get_url(&url).unwrap();
println!("url={}, response={}", &url, &resp_str);
}
The ::mtx module of Zoea adds some syntactic sugar around nalgebra to make it easy to create matrices of variable sizes and types. Matrix multiplication and linear algebra made easy.
use zoea::mtx;
// Create a 3x1000 f32 random matrix with values between -1 and 1
// Create a 1000x4 f32 random matrix with values between 5 and 25
let a = mtx::new_f32_random(3, 1000, -1f32, 1f32); //type = mtx::DMatrix \< f32>
let b = mtx::new_f32_random(1000, 4, 5f32, 25f32); // type = mtx::DMatrix \< f32>
// multiply a and b and print the result
let c = a * b;
println!("{}", c);
// take one of the values and assign it to a float
let select_element: f32 = c[(1,3)];
The Zoea kv_database (key-value) uses a sqlite backend for simple operations.
use zoea::kv_database;
fn main() {
let db = "MyTestDatabase"; // can be &str or &String
let key = "Key1"; // can be &str or &String
let value = "Value you want to insert"; // can be &str or &String
// SET the value of key in database db
kv_database::set(&db, &key, &value);
// GET the value of key in database db
let same_value = kv_database::get(&db, &key);
println!("returned value = {}", same_value);
// LIST keys in database db
let keys = kv_database::list_keys(&db);
// GETting an empty key returns an empty string
let non_key = "KeyThatDoesNotExist";
let non_value = kv_database::get(&db, &non_key); // returns String::new();
// DELETE a key in database db
kv_database::delete(&db, &key);
}
use zoea::nlp;
fn main() {
let sentence = String::from("Today I walked slowly to the garden in San Diego.");
let tokenized_bigrams = nlp::text_token_bigrams(&sentence);
for bigram in tokenized_bigrams {
println!("bigram= {}", bigram);
}
}
use zoea::nlp;
let port_stems = nlp::porter_stems("Totally dude!");
assert_eq!(port_stems[0], "total");
use zoea::hash;
fn main() {
let mystring = String::from("Here is some string to hash"); // can be &str or &String
let myhash = hash::hash_string(&mystring);
println!("the hash is = {}", myhash);
}