summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorVoker57 <voker57@gmail.com>2009-12-16 14:59:40 +0300
committerVoker57 <voker57@gmail.com>2010-01-26 00:41:07 +0300
commit1a3201c4a601f45211acabab053ee47a8f7041fc (patch)
tree582e4ea8326f70dfd861af110e172bd2644efe3b /data/rbot
parentc87ce00ad85418741f2dea836cc3fcb12efdb5e7 (diff)
markov: Moved weighted pick to separate function
Diffstat (limited to 'data/rbot')
-rwxr-xr-xdata/rbot/plugins/markov.rb18
1 files 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