From be80010811086875f76fce822f58aac1889fee93 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 30 Jul 2007 10:37:57 +0200 Subject: [PATCH] Don't add useless chains --- mark2.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mark2.rb b/mark2.rb index 8d339b2..62563fa 100644 --- a/mark2.rb +++ b/mark2.rb @@ -114,13 +114,16 @@ class MarkovChainer end def add_one(sym) - s = sym.to_sym rescue nil - @mkv[nil].increase(s) + # Don't add nil to order 0 + return unless sym + @mkv[nil].increase(sym.to_sym) end def add_before(array, prev) raise "Not enough words in new data" if array.empty? raise "Too many words in new data" if array.size > @max_order + # Don't add prev to chains whose first element is nil + return unless array.first h = @mkv[array.dup] h[:prev].increase(prev) end @@ -128,6 +131,8 @@ class MarkovChainer def add_after(array, nxt) raise "Not enough words in new data" if array.empty? raise "Too many words in new data" if array.size > @max_order + # Don't add next to chains whose last element is nil + return unless array.last h = @mkv[array.dup] h[:next].increase(nxt) end -- 2.32.0.93.g670b81a890