LavirtheWhiolet / markov-chain-bot-module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Markov chain chat bot

A chat bot utilizing Markov chains. It speaks Russian and English.

How to build

  • Install Ruby 1.9.1 or latest.
  • Give command rake in this directory.
  • You have got a Ruby gem!

Examples

Basic usage:

require 'markov_chain_chat_bot'

bot = MarkovChainChatBot.from(Hash.new)
bot.learn("one two three two one")
bot.answer("count up and down please")
  #=> "one two three two three two one two one two three two one two one"
bot.learn("three four six")
bot.answer("count from three please")
  #=> "three two one two one two three four six"

One may save the bot's knowledge into key-value storage:

require 'markov_chain_chat_bot'
require 'auto_marshalling_map'
require 'gdbm'

# 1.
kvs = GDBM.open("chat_bot.dat")
bot = MarkovChainChatBot.from(AutoMarhsallingMap.new(kvs))
bot.learn("one two three two one")
kvs.close()

# 2.
kvs = GDBM.open("chat_bot.dat")
bot = MarkovChainChatBot.from(AutoMarhsallingMap.new(kvs))
bot.answer("count up and down please")
  #=> "one two three two three two three two one two one"

Credits

About


Languages

Language:Ruby 100.0%