markov-algorithms

Crates.iomarkov-algorithms
lib.rsmarkov-algorithms
version0.4.6
sourcesrc
created_at2022-08-15 18:43:42.442722
updated_at2022-11-07 13:22:55.224406
descriptionRust implementation of Markov algorithms.
homepage
repositoryhttps://github.com/quixoticaxis/markov-algorithms
max_upload_size
id646092
size134,237
Sergey Ivanov (quixoticaxis)

documentation

https://docs.rs/markov-algorithms

README

markov-algorithms

Rust implementation of Markov algorithms executor.

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:

markov-algorithms = "0.4"

Define a scheme of the algorithm:

use std::str;
use markovalgorithms::prelude::*;

let alphabet = str::parse::<Alphabet>("abc").unwrap().extend('d').unwrap();
let scheme = AlgorithmSchemeBuilder::new()
    .with_alphabet(alphabet)
    .build_with_formula_definitions(["a→⋅d"].into_iter())
    .unwrap();

Apply the scheme:

let result = scheme.apply("abc", 1).unwrap();

assert_eq!("dbc", result.word());
assert_eq!(1, result.steps_done());

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:

let mut iterator = scheme.get_application_iterator("abc").unwrap();

assert_eq!("dbc", iterator.next().unwrap().word());
assert_eq!(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. Launch markovalgorithms-cli with --help flag to see the descriptions of parameters and usage example.

Commit count: 47

cargo fmt