Crates.io | structured-language-form |
lib.rs | structured-language-form |
version | 0.3.0 |
source | src |
created_at | 2024-11-22 03:32:14.283766 |
updated_at | 2024-12-06 01:44:15.274978 |
description | A Rust crate for representing and working with various poetic meters. |
homepage | https://github.com/klebs6/klebs-general |
repository | https://github.com/klebs6/klebs-general |
max_upload_size | |
id | 1456991 |
size | 15,945 |
The structured_language_form
crate provides a comprehensive and structured way to work with various poetic and literary forms, enabling applications in natural language processing, creative writing, and education. Whether you're generating poetry, analyzing text, or exploring structured language, this crate offers a robust foundation for handling a variety of structured language forms.
#[ai]
attribute, providing concise descriptions of the form.Cargo.toml
[dependencies]
structured_language_form = "0.1.0"
rand = "0.8" # Required for random generation
serde = { version = "1.0", features = ["derive"] } # Optional for serialization
use structured_language_form::StructuredLanguageForm;
use rand::SeedableRng;
use rand::rngs::StdRng;
fn main() {
// Generate a specific language form
let haiku = StructuredLanguageForm::Haiku;
println!("Selected form: {:?}", haiku);
// Generate a random language form with a seeded RNG
let mut rng = StdRng::seed_from_u64(42);
let random_form = StructuredLanguageForm::random_with_rng(&mut rng);
println!("Random form: {:?}", random_form);
// Serialize and deserialize (optional, requires serde feature)
#[cfg(feature = "serde")]
{
let serialized = serde_json::to_string(&random_form).unwrap();
println!("Serialized: {}", serialized);
let deserialized: StructuredLanguageForm =
serde_json::from_str(&serialized).unwrap();
println!("Deserialized: {:?}", deserialized);
}
}
Below is a sample of the structured language forms included in the crate:
Refer to the source code for the full list.
The crate supports deterministic random generation using the rand
crate. This feature is ideal for testing and applications where reproducibility is crucial.
Example:
let mut rng = StdRng::seed_from_u64(12345);
let random_form = StructuredLanguageForm::random_with_rng(&mut rng);
With the serde
feature enabled, you can serialize and deserialize StructuredLanguageForm
instances into formats like JSON:
use serde_json;
use structured_language_form::StructuredLanguageForm;
let form = StructuredLanguageForm::Sonnet;
let serialized = serde_json::to_string(&form).unwrap();
let deserialized: StructuredLanguageForm = serde_json::from_str(&serialized).unwrap();
This crate integrates well with AI tools, natural language processing frameworks, and creative writing applications. The annotations (#[ai]
) make it especially suitable for AI-driven systems that require metadata or descriptions of the variants.
Contributions to the crate are welcome! Please open an issue or submit a pull request on the GitHub repository.
This crate is licensed under the MIT License. See the LICENSE
file for details.