diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-28 11:59:17 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-28 12:00:30 +0100 |
commit | 16336b4a240a4265d1f2df1e30d7b68d3a924287 (patch) | |
tree | c616ab9187c85c7a3ead3675bef727a741826bf0 | |
parent | 2656473b50e0d6afafeb50fee2d276fed093568c (diff) |
markov: refactor triplet learning
-rwxr-xr-x | data/rbot/plugins/markov.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/data/rbot/plugins/markov.rb b/data/rbot/plugins/markov.rb index 46f78c93..d03b6ede 100755 --- a/data/rbot/plugins/markov.rb +++ b/data/rbot/plugins/markov.rb @@ -307,18 +307,21 @@ class MarkovPlugin < Plugin random_markov(m, message) unless m.replied? end + def learn_triplet(word1, word2, word3) + k = "#{word1} #{word2}" + @registry[k] = @registry[k].push(word3) + end + def learn_line(message) # debug "learning #{message}" wordlist = message.split(/\s+/) return unless wordlist.length >= 2 word1, word2 = :nonword, :nonword + wordlist << :nonword wordlist.each do |word3| - k = "#{word1} #{word2}" - @registry[k] = @registry[k].push(word3) + learn_triplet(word1, word2, word3) word1, word2 = word2, word3 end - k = "#{word1} #{word2}" - @registry[k] = @registry[k].push(:nonword) end # TODO allow learning from URLs |