lib/ankusa/hbase_storage.rb in ankusa-0.0.14 vs lib/ankusa/hbase_storage.rb in ankusa-0.0.15

- old
+ new

@@ -24,11 +24,11 @@ def reset drop_tables init_tables end - + def drop_tables freq_table.delete summary_table.delete @stable = nil @ftable = nil @@ -67,24 +67,26 @@ def get_total_word_count(klass) @klass_word_counts.fetch(klass) { @klass_word_counts[klass] = summary_table.get(klass, "totals:wordcount").first.to_i64.to_f } end - + def get_doc_count(klass) @klass_doc_counts.fetch(klass) { - @klass_doc_counts[klass] = summary_table.get(klass, "totals:doccount").first.to_i64.to_f + totals = summary_table.get(klass, "totals:doccount") + totals = (totals.size === 0) ? 0 : totals.first.to_i64.to_f + @klass_doc_counts[klass] = totals } end def incr_word_count(klass, word, count) size = freq_table.atomic_increment word, "classes:#{klass.to_s}", count # if this is a new word, increase the klass's vocab size. If the new word # count is 0, then we need to decrement our vocab size if size == count summary_table.atomic_increment klass, "totals:vocabsize" elsif size == 0 - summary_table.atomic_increment klass, "totals:vocabsize", -1 + summary_table.atomic_increment klass, "totals:vocabsize", -1 end size end def incr_total_word_count(klass, count)