Class: Classifier::WordList
Overview
This class keeps a word => index mapping. It is used to map stemmed words to dimensions of a vector.
Instance Method Summary collapse
-
#[](lookup) ⇒ Object
Returns the dimension of the word or nil if the word is not in the space.
-
#add_word(word) ⇒ Object
Adds a word (if it is new) and assigns it a unique dimension.
-
#initialize ⇒ WordList
constructor
A new instance of WordList.
-
#size ⇒ Object
Returns the number of words mapped.
- #word_for_index(ind) ⇒ Object
Constructor Details
#initialize ⇒ WordList
Returns a new instance of WordList.
14 15 16 |
# File 'lib/classifier/lsi/word_list.rb', line 14 def initialize @location_table = {} end |
Instance Method Details
#[](lookup) ⇒ Object
Returns the dimension of the word or nil if the word is not in the space.
29 30 31 32 |
# File 'lib/classifier/lsi/word_list.rb', line 29 def [](lookup) term = lookup @location_table[term] end |
#add_word(word) ⇒ Object
Adds a word (if it is new) and assigns it a unique dimension.
21 22 23 24 |
# File 'lib/classifier/lsi/word_list.rb', line 21 def add_word(word) term = word @location_table[term] = @location_table.size unless @location_table[term] end |
#size ⇒ Object
Returns the number of words mapped.
42 43 44 |
# File 'lib/classifier/lsi/word_list.rb', line 42 def size @location_table.size end |
#word_for_index(ind) ⇒ Object
35 36 37 |
# File 'lib/classifier/lsi/word_list.rb', line 35 def word_for_index(ind) @location_table.invert[ind] end |