- 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)
+ def grouped_selector(words, o={})
+ offset= o[:offset].to_i
+ wds = []
+ cols = []
+ words.length.times do |i|
+ cols << word(i)
+ wds << words[i].quoted
+ end
+ if o.key?(:chance)
+ cols << "chance"
+ wds << o[:chance].to_i
+ end
+ return [cols.sql_group, wds.sql_group]
+ end
+
+ def add_one(sym)
+ # Don't add nil to order 0
+ return unless sym
+ @db.transaction do |db|
+ if db.get_first_value("select chance from order0 where word0=?1", sym)
+ db.execute("update order0 set chance=chance+1 where word0=?1", sym)
+ else
+ db.execute("insert into order0 (word0, chance) values (?1, 1)", sym)
+ end
+ end
+ # puts @db.execute("select * from order0 where word0=?1", sym).inspect