Class: Ankusa::MemoryStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/ankusa/memory_storage.rb

Instance Method Summary collapse

Constructor Details

#initializeMemoryStorage

Returns a new instance of MemoryStorage.



4
5
6
# File 'lib/ankusa/memory_storage.rb', line 4

def initialize
  init_tables
end

Instance Method Details

#classnamesObject



8
9
10
# File 'lib/ankusa/memory_storage.rb', line 8

def classnames
  @total_doc_counts.keys
end

#closeObject



64
65
# File 'lib/ankusa/memory_storage.rb', line 64

def close
end

#doc_count_totalsObject



60
61
62
# File 'lib/ankusa/memory_storage.rb', line 60

def doc_count_totals
  @total_doc_counts
end

#drop_tablesObject



16
17
# File 'lib/ankusa/memory_storage.rb', line 16

def drop_tables
end

#get_doc_count(klass) ⇒ Object



43
44
45
# File 'lib/ankusa/memory_storage.rb', line 43

def get_doc_count(klass)
  @total_doc_counts[klass]
end

#get_total_word_count(klass) ⇒ Object



39
40
41
# File 'lib/ankusa/memory_storage.rb', line 39

def get_total_word_count(klass)
  @total_word_counts[klass]
end

#get_vocabulary_sizesObject



27
28
29
30
31
32
33
# File 'lib/ankusa/memory_storage.rb', line 27

def get_vocabulary_sizes
  count = Hash.new 0
  @freqs.each { |w, ks|
    ks.keys.each { |k| count[k] += 1 }
  }
  count
end

#get_word_counts(word) ⇒ Object



35
36
37
# File 'lib/ankusa/memory_storage.rb', line 35

def get_word_counts(word)
  @freqs.fetch word, Hash.new(0)
end

#incr_doc_count(klass, count) ⇒ Object



56
57
58
# File 'lib/ankusa/memory_storage.rb', line 56

def incr_doc_count(klass, count)
  @total_doc_counts[klass] += count
end

#incr_total_word_count(klass, count) ⇒ Object



52
53
54
# File 'lib/ankusa/memory_storage.rb', line 52

def incr_total_word_count(klass, count)
  @total_word_counts[klass] += count
end

#incr_word_count(klass, word, count) ⇒ Object



47
48
49
50
# File 'lib/ankusa/memory_storage.rb', line 47

def incr_word_count(klass, word, count)
  @freqs[word] ||= Hash.new(0)
  @freqs[word][klass] += count
end

#init_tablesObject



19
20
21
22
23
24
25
# File 'lib/ankusa/memory_storage.rb', line 19

def init_tables
  @freqs = {}
  @total_word_counts = Hash.new(0)
  @total_doc_counts = Hash.new(0)
  @klass_word_counts = {}
  @klass_doc_counts = {}
end

#resetObject



12
13
14
# File 'lib/ankusa/memory_storage.rb', line 12

def reset
  init_tables
end