#algorithm #markov #scheme #markov-algorithm

bin+lib markov-algorithms

Rust 实现的马尔可夫算法

7 个版本

0.4.6 2022年11月7日
0.4.5 2022年10月16日
0.4.4 2022年9月1日
0.4.2 2022年8月21日
0.1.0 2022年8月15日

#818算法

每月 27 次下载

GPL-3.0 许可证

80KB
1.5K SLoC

markov-algorithms

Rust 实现的马尔可夫算法执行器。

这个包完全是出于教育目的而创建的,并且以 GPL-3.0 许可证发布。

文档可以在 docs.rs 上找到。

您可以将该包用作库。

将依赖项添加到 Cargo.toml

markov-algorithms = "0.4"

定义算法方案

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();

应用方案

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

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

您也可以将方案一次性应用以检查算法的单个步骤或获取迭代器以逐步应用方案

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

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

示例

请参阅 /tests 文件夹以获取更复杂的方案。

工具

您可以使用基于 clap 的简单 CLI 工具来执行从 UTF-8 文件中加载的方案定义的算法。

使用 cargo 安装

cargo install markov-algorithms

它将安装 markovalgorithms-cli 工具。使用 --help 标志启动 markovalgorithms-cli 以查看参数描述和用法示例。

依赖项

~4–12MB
~135K SLoC