Sha256: 9e35c0354b9b5b89b864a4cccc3c5095eda3174d33952a685a66889762cdb11c

Contents?: true

Size: 864 Bytes

Versions: 7

Compression:

Stored size: 864 Bytes

Contents

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

module ClassifierReborn
  # 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

7 entries across 7 versions & 2 rubygems

Version Path
classifier-reborn-2.0.4 lib/classifier-reborn/lsi/word_list.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/classifier-reborn-2.0.3/lib/classifier-reborn/lsi/word_list.rb
classifier-reborn-2.0.3 lib/classifier-reborn/lsi/word_list.rb
classifier-reborn-2.0.2 lib/classifier-reborn/lsi/word_list.rb
classifier-reborn-2.0.1 lib/classifier-reborn/lsi/word_list.rb
classifier-reborn-2.0.0 lib/classifier-reborn/lsi/word_list.rb
classifier-reborn-2.0.0.rc1 lib/classifier-reborn/lsi/word_list.rb