From 1a3201c4a601f45211acabab053ee47a8f7041fc Mon Sep 17 00:00:00 2001 From: Voker57 Date: Wed, 16 Dec 2009 14:59:40 +0300 Subject: markov: Moved weighted pick to separate function --- data/rbot/plugins/markov.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/data/rbot/plugins/markov.rb b/data/rbot/plugins/markov.rb index e8ddee49..eeb2acc0 100755 --- a/data/rbot/plugins/markov.rb +++ b/data/rbot/plugins/markov.rb @@ -258,16 +258,16 @@ class MarkovPlugin < Plugin debug 'learning thread closed' end - # if passed a pair, pick a word from the registry using the pair as key. - # otherwise, pick a word from an given list + # pick a word from the registry using the pair as key. def pick_word(word1, word2=MARKER, chainz=@chains) - if word1.kind_of? Array - wordlist = word1 - else - k = "#{word1} #{word2}" - return MARKER unless chainz.key? k - wordlist = chainz[k] - end + k = "#{word1} #{word2}" + return MARKER unless chainz.key? k + wordlist = chainz[k] + pick_word_from_list wordlist + end + + # pick a word from weighted hash + def pick_word_from_list(wordlist) total = wordlist.first hash = wordlist.last return MARKER if total == 0 -- cgit v1.2.3