markov-algorithms

Rust implementation of Markov algorithms.

This crate is created purely for educational purposes and is published under GPL-3.0 license.

The documentation can be found on docs.rs.

Library

You can use the crate as a library.

Add the dependency to Cargo.toml: toml markov-algorithms = "0.4"

Define a scheme of the algorithm: ```rust use std::str; use markovalgorithms::prelude::*;

let alphabet = str::parse::("abc").unwrap().extend('d').unwrap(); let scheme = AlgorithmSchemeBuilder::new() .withalphabet(alphabet) .buildwithformuladefinitions(["a→⋅d"].into_iter()) .unwrap(); Apply the scheme: rust let result = scheme.apply("abc", 1).unwrap();

asserteq!("dbc", result.word()); asserteq!(1, result.stepsdone()); You may also apply the scheme once to inspect a single step of the algorithm or get an iterator to apply the scheme step by step: ```rust let mut iterator = scheme.getapplication_iterator("abc").unwrap();

asserteq!("dbc", iterator.next().unwrap().word()); asserteq!(None, iterator.next()) ```

Examples

See the /tests forlder for more complex schemes.

Tool

You can use a simple clap-based CLI tool to execute algorithms defined by the schemes loaded from UTF-8 files.

Install with cargo: cargo install markov-algorithms It would install markovalgorithms-cli tool.