Sha256: d61670838f2cbdf9d18c018f2cf5c5d6cfe26148df1538d9829c6fb990df129b

Contents?: true

Size: 884 Bytes

Versions: 33

Compression:

Stored size: 884 Bytes

Contents

# Author::    David Fayram  (mailto:dfayram@lensmen.net)
# Copyright:: Copyright (c) 2005 David Fayram II
# License::   LGPL

module Classifier  
  # This class keeps a word => index mapping. It is used to map stemmed words
  # to dimensions of a vector.
    
  class WordList
    def initialize
      @location_table = Hash.new
    end
    
    # Adds a word (if it is new) and assigns it a unique dimension.
    def add_word(word)
      term = word
      @location_table[term] = @location_table.size unless @location_table[term]
    end
    
    # Returns the dimension of the word or nil if the word is not in the space.
    def [](lookup)
      term = lookup
      @location_table[term]
    end
    
    def word_for_index(ind)
      @location_table.invert[ind]
    end
    
    # Returns the number of words mapped.
    def size
      @location_table.size
    end
    
  end
end

Version data entries

33 entries across 33 versions & 12 rubygems

Version Path
francois-classifier-1.3.4 lib/classifier/lsi/word_list.rb
francois-classifier-1.3.6 lib/classifier/lsi/word_list.rb
otherinbox-classifier-1.3.1.1 lib/classifier/lsi/word_list.rb
yury-classifier-1.3.1 lib/classifier/lsi/word_list.rb
yury-classifier-1.3.2 lib/classifier/lsi/word_list.rb
yury-classifier-1.3.3 lib/classifier/lsi/word_list.rb
yury-classifier-1.3.4 lib/classifier/lsi/word_list.rb
yury-classifier-1.3.5 lib/classifier/lsi/word_list.rb
classifier-fork-1.3.4 lib/classifier/lsi/word_list.rb
classifier-1.3.4 lib/classifier/lsi/word_list.rb
classifier_atsukamoto-0.0.5 lib/classifier/lsi/word_list.rb
classifier_atsukamoto-0.0.4 lib/classifier/lsi/word_list.rb
classifier_atsukamoto-0.0.3 lib/classifier/lsi/word_list.rb
classifier_atsukamoto-0.0.2 lib/classifier/lsi/word_list.rb
classifier_atsukamoto-0.0.1 lib/classifier/lsi/word_list.rb
otherinbox-classifier-1.3.1.2.20121218.2 lib/classifier/lsi/word_list.rb
otherinbox-classifier-1.3.1.2.20121218 lib/classifier/lsi/word_list.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/classifier-1.3.3/lib/classifier/lsi/word_list.rb
logankoester-classifier-1.4.3 lib/classifier/lsi/word_list.rb
classifier-1.3.3 lib/classifier/lsi/word_list.rb