Class: ClassifierReborn::WordList
- Inherits:
-
Object
- Object
- ClassifierReborn::WordList
- Defined in:
- lib/classifier-reborn/lsi/word_list.rb
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.
12 13 14 |
# File 'lib/classifier-reborn/lsi/word_list.rb', line 12 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.
22 23 24 |
# File 'lib/classifier-reborn/lsi/word_list.rb', line 22 def [](lookup) @location_table[lookup] end |
#add_word(word) ⇒ Object
Adds a word (if it is new) and assigns it a unique dimension.
17 18 19 |
# File 'lib/classifier-reborn/lsi/word_list.rb', line 17 def add_word(word) @location_table[word] = @location_table.size unless @location_table[word] end |
#size ⇒ Object
Returns the number of words mapped.
31 32 33 |
# File 'lib/classifier-reborn/lsi/word_list.rb', line 31 def size @location_table.size end |
#word_for_index(ind) ⇒ Object
26 27 28 |
# File 'lib/classifier-reborn/lsi/word_list.rb', line 26 def word_for_index(ind) @location_table.invert[ind] end |