markov_chain_chat_bot 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +5 -5
- data/lib/markov_chain_chat_bot.rb +16 -4
- metadata +1 -1
data/README
CHANGED
@@ -12,9 +12,9 @@ A chat bot utilizing Markov chains. It speaks Russian and English.
|
|
12
12
|
|
13
13
|
Basic usage:
|
14
14
|
|
15
|
-
require '
|
15
|
+
require 'markov_chain_chat_bot'
|
16
16
|
|
17
|
-
bot =
|
17
|
+
bot = MarkovChainChatBot.from(Hash.new)
|
18
18
|
bot.learn("one two three two one")
|
19
19
|
bot.answer("count up and down please")
|
20
20
|
#=> "one two three two three two one two one two three two one two one"
|
@@ -24,19 +24,19 @@ Basic usage:
|
|
24
24
|
|
25
25
|
One may save the bot's knowledge into key-value storage:
|
26
26
|
|
27
|
-
require '
|
27
|
+
require 'markov_chain_chat_bot'
|
28
28
|
require 'auto_marshalling_map'
|
29
29
|
require 'gdbm'
|
30
30
|
|
31
31
|
# 1.
|
32
32
|
kvs = GDBM.open("chat_bot.dat")
|
33
|
-
bot =
|
33
|
+
bot = MarkovChainChatBot.from(AutoMarhsallingMap.new(kvs))
|
34
34
|
bot.learn("one two three two one")
|
35
35
|
kvs.close()
|
36
36
|
|
37
37
|
# 2.
|
38
38
|
kvs = GDBM.open("chat_bot.dat")
|
39
|
-
bot =
|
39
|
+
bot = MarkovChainChatBot.from(AutoMarhsallingMap.new(kvs))
|
40
40
|
bot.answer("count up and down please")
|
41
41
|
#=> "one two three two three two three two one two one"
|
42
42
|
|
@@ -10,8 +10,9 @@ class MarkovChainChatBot
|
|
10
10
|
private_class_method :new
|
11
11
|
|
12
12
|
#
|
13
|
-
# +data+ is a map. It may be empty, in this case a brand new
|
14
|
-
# created. +data+ becomes owned by the returned
|
13
|
+
# +data+ is a map. It may be empty, in this case a brand new
|
14
|
+
# MarkovChainChatBot is created. +data+ becomes owned by the returned
|
15
|
+
# MarkovChainChatBot.
|
15
16
|
#
|
16
17
|
# +answer_limit+ is maximum size of the result of #answer().
|
17
18
|
#
|
@@ -32,10 +33,21 @@ class MarkovChainChatBot
|
|
32
33
|
@markov_chain.data
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
#
|
37
|
+
# +message+ is String.
|
38
|
+
#
|
39
|
+
# It returns this (modified) MarkovChainChatBot.
|
40
|
+
#
|
41
|
+
def learn(message)
|
42
|
+
@markov_chain.append!(tokenize(message)).append!([EndOfMessage.new])
|
43
|
+
return self
|
37
44
|
end
|
38
45
|
|
46
|
+
#
|
47
|
+
# +question+ is String.
|
48
|
+
#
|
49
|
+
# It returns String.
|
50
|
+
#
|
39
51
|
def answer(question)
|
40
52
|
answer = ""
|
41
53
|
previous_token = nil
|