class Classifier::WordList

This class keeps a word => index mapping. It is used to map stemmed words to dimensions of a vector.

Public Class Methods

new() click to toggle source
# File lib/classifier/lsi/word_list.rb, line 10
def initialize
  @location_table = Hash.new
end

Public Instance Methods

[](lookup) click to toggle source

Returns the dimension of the word or nil if the word is not in the space.

# File lib/classifier/lsi/word_list.rb, line 21
def [](lookup)
  term = lookup
  @location_table[term]
end
add_word(word) click to toggle source

Adds a word (if it is new) and assigns it a unique dimension.

# File lib/classifier/lsi/word_list.rb, line 15
def add_word(word)
  term = word
  @location_table[term] = @location_table.size unless @location_table[term]
end
size() click to toggle source

Returns the number of words mapped.

# File lib/classifier/lsi/word_list.rb, line 31
def size
  @location_table.size
end
word_for_index(ind) click to toggle source
# File lib/classifier/lsi/word_list.rb, line 26
def word_for_index(ind)
  @location_table.invert[ind]
end