1 个不稳定版本

0.1.0 2022年11月9日

#18 in #markov

BSD-3-Clause

27KB
432

Rustkov

Rustkov 是一个旨在使用马尔可夫链构建聊天机器人的Rust库。

示例

use rustkov::prelude::*;

fn main() -> Result<()> {
    // Create a new brain which contains the markov chain
    let mut brain = Brain::new()
        // train him with a dataset
        .from_dataset("path/to/your/dataset.txt")?
        .get();

    // As we didn't specify a config file to the brain,
    // we need to adjust config options here.
    // For instance, let's make it so it can learn from inputs.
    brain.config.training = true;

    // `brain.generate` returns an option, as the reply_chance config might
    // be less than 1.
    if let Some(response) = brain.generate("Hello there!")? {
        println!("{}", response);
    }

    // Get a reference to a BrainStats struct, computing statistics for a given brain
    let stats = brain.stats();

    println!("I know {} words!", stats.get_total_words());

    Ok(())
}

安装

将以下内容添加到您的 Cargo.toml 文件中

[dependencies]
rustkov = "0.1.0"

依赖项

~4MB
~82K SLoC