Class: Reclassifier::WordList

Inherits:
Object
  • Object
show all
Defined in:
lib/reclassifier/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

Constructor Details

#initializeWordList

Returns a new instance of WordList.



6
7
8
# File 'lib/reclassifier/word_list.rb', line 6

def initialize
  @location_table = Hash.new
end

Instance Method Details

#[](lookup) ⇒ Object

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



17
18
19
20
# File 'lib/reclassifier/word_list.rb', line 17

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.



11
12
13
14
# File 'lib/reclassifier/word_list.rb', line 11

def add_word(word)
  term = word
  @location_table[term] = @location_table.size unless @location_table[term]
end

#sizeObject

Returns the number of words mapped.



27
28
29
# File 'lib/reclassifier/word_list.rb', line 27

def size
  @location_table.size
end

#word_for_index(ind) ⇒ Object



22
23
24
# File 'lib/reclassifier/word_list.rb', line 22

def word_for_index(ind)
  @location_table.invert[ind]
end