human_language_toolkit_chatbot

Crates.iohuman_language_toolkit_chatbot
lib.rshuman_language_toolkit_chatbot
version0.1.1
sourcesrc
created_at2021-06-13 08:43:01.537557
updated_at2021-06-13 08:52:33.606337
descriptionNLTK like chatbot made with pure rust.
homepagehttps://github.com/HectorPulido/human-language-toolkit-chatbot
repositoryhttps://github.com/HectorPulido/human-language-toolkit-chatbot
max_upload_size
id409511
size15,363
Hector Pulido (HectorPulido)

documentation

README

HLTK chatbot

This is a regex powered chatbot made in rust, it is based in NLTK https://github.com/nltk/nltk/blob/develop/nltk/chat/util.py

How to install

add to your Cargo.toml file

[dependencies]
...
human_language_toolkit_chatbot = "0.1.0"
...

You can find the updated version at https://crates.io/crates/human_language_toolkit_chatbot

How to use it

You can read from a json file.

use human_language_toolkit_chatbot::{Chatbot, ChatbotError, CompiledChatbot};
...
let suntsu = Chatbot::from_file(String::from("bots/suntsu.json")).unwrap();
...

Also you can create the bot by programming.

...
let mut pairs: Vec<(String, Vec<String>)> = Vec::new();
pairs.push((
    String::from(r"Hello(.*)"),
    vec![
        String::from("Hello... I'm glad you could drop by today."),
        String::from("Hi there... how are you today?"),
        String::from("Hello, how are you feeling today?"),
    ],
));
pairs.push((
    String::from(r"(.*) sorry (.*)"),
    vec![
        String::from("There are many times when no apology is needed."),
        String::from("What feelings do you have when you apologize?"),
    ],
));
...
let fallback = vec![String::from("Sorry I didn't understand")];
let reflections = Chatbot::default_reflections();

let eliza = Chatbot {
    pairs,
    fallback,
    reflections,
};

// You can save your model in a .json file
match eliza.to_file(String::from("bots/eliza.json")) {
    Ok(_) => (),
    Err(e) => println!("error at {}", e),
}

let eliza = eliza.compile();

You can talk with the bot with the function respond but you can also use the converse function to make an infinity conversation.

Let's connect 😋

Hector's LinkedIn     Hector's Twitter     Hector's Twitch     Hector's Youtube    

Commit count: 9

cargo fmt